从父组件访问子路由参数

时间:2019-06-05 13:11:16

标签: angular angular-routing

此代码有效,但是当路线改变时不会更新,如何完成? 来自父组件的代码:

  ......
  searchType : string;
  searchTypeSubscription : Subscription;
  constructor(
    private route: ActivatedRoute,
    private router: Router,
  ) { }

  ngOnInit() {
    this.searchTypeSubscription = this.route.firstChild.paramMap.subscribe(params => {
      this.searchType = params.get("type")
    })
      console.log(this.searchType);
  }
  .......

路由的定义如下:

const ParentRoutes: Routes = [
  {
    path: 'parent', component: ParentComponent,
    children: [
      { 
        path: 'search/:type', component: ChildSearchComponent 
      },

0 个答案:

没有答案