在Angular 2中处理嵌套订阅的正确方法

时间:2017-08-14 19:53:24

标签: angular angular2-routing angular2-observables

我正在尝试为具有查询参数和可观察对象的角度2 Web应用程序创建分页。我已经掌握了下面的代码,但我觉得嵌套订阅并不是一个好主意。有一个更好的方法吗?

  blogs:any;
  page = 0;
  sub;

  ngOnInit() {
    this.sub = this.route.queryParams
      .subscribe(params => {
           this.page = +params['page'] || 0;
           this.requestService.getData('posts', '..query string...')
       .subscribe(data => this.blogs = data.data);
     });
  }
  nextPage() {
      this.router.navigate(['./'], { queryParams: { page: this.page + 1 }, relativeTo: this.route }   );
   }

1 个答案:

答案 0 :(得分:2)

您可以使用<?php ini_set('display_errors', "Off"); $employee_id = $_POST['employee_id']; $note_name = $_POST['name']; if(!empty($employee_id)) { $objBreeze = new Breeze(); //$objBreeze->createEmployee($employee_id, $note_name); // ^^^^^^^^^^^^^^^^^^^^^^^^ // my guess would be you need somthing like this // I have to guess as you dont show what // $this->db->prepareInsert($params); does $params = array('employee_id' => $_POST['employee_id'], 'name' => $_POST['name']); $objBreeze->createEmployee($params); } 链接observable。

.switchMap