How do I pass data to Angular routed components?

前端 未结 16 1346
挽巷
挽巷 2020-11-22 08:03

In one of my Angular 2 routes\'s templates (FirstComponent) I have a button

first.component.html

16条回答
  •  暖寄归人
    2020-11-22 08:42

    Some super smart person (tmburnell) that is not me suggests re-writing the route data:

    let route = this.router.config.find(r => r.path === '/path');
    route.data = { entity: 'entity' };
    this.router.navigateByUrl('/path');
    

    As seen here in the comments.

    I hope someone will find this useful

提交回复
热议问题