How to get current route custom data in angular 2?

后端 未结 11 1840
旧时难觅i
旧时难觅i 2020-12-05 06:21

I have set up routes is like below

const appRoutes: Routes = [
  {
    path: \'login\',
    component: LoginComponent,
    data: {
      title: \'Login TTX\         


        
11条回答
  •  既然无缘
    2020-12-05 07:23

    this.router.events.subscribe((event: any) => {
            this.pageTitle = this.titleService.getTitle();
            // check instanceof  ChildActivationEnd  || ChildActivationStart
            if (event instanceof ChildActivationStart) {
                let pageIcon = event.snapshot?.firstChild?.children[0]?.data['icon'];
                this.pageIcon = pageIcon ? pageIcon : this.pageIcon;
            }
        })
    

提交回复
热议问题