Angular 6-将route.params与route.parent.params组合

时间:2018-06-25 20:23:26

标签: angular rxjs6

为什么这不起作用?

import { forkJoin } from 'rxjs';
import { ActivatedRoute } from '@angular/router';

constructor(
  private route: ActivatedRoute
) {}

ngOnInit(): void {

  let parent = this.route.parent.params;
  let child = this.route.params;

  forkJoin(
     parent,
     child,
     (p, c) => {
        console.log(p);
        console.log(c);
     }
  )
}

FYI(rxjs6)

1 个答案:

答案 0 :(得分:3)

import { combineLatest } from 'rxjs'; 
import { ActivatedRoute } from '@angular/router';

constructor(
  private route: ActivatedRoute
) {}

ngOnInit(): void {

combineLatest(
      this.route.parent.params,
      this.route.params
).subscribe(
   ([p, c]) => {
      console.log(p);
      console.log(c);
   }
);
}