0

I have a route like below:

{ path: 'contact-us', component: ContactUsComponent , data: {isPrivate: false}},

When I try to get the above isPrivate value on ngOnInit() of ContactUsComponent.ts, it gives undefined:

constructor(private route: ActivatedRoute) {}
..
ngOnInit() {
 this._private = this.route.snapshot.data['isPrivate'];
}
4

3 回答 3

0

check this out

constructor(router:Router, route: ActivatedRoute) {
    router.events
      .filter(e => e instanceof NavigationEnd)
      .forEach(e => {
        this.title = route.root.firstChild.snapshot.data['PageName'];
    });
}
于 2019-06-18T10:10:12.287 回答
0

Maybe try something like:-

constructor(private route: ActivatedRoute) {}
OnInit() {
  this.route.data.subscribe(private => this._private = private);
}
于 2019-06-18T10:13:00.883 回答
-1

Try getting the property right in the constructor:

constructor(private route: ActivatedRoute) {
    this._private = this.route.snapshot.data['isPrivate'];
}
于 2019-06-18T10:11:04.910 回答