我有一个辅助导航,其中的数据需要根据路线进行更改。请找到下图。
所有需要显示在组件上的数据存储如下。
export const Items: SecondaryNavItems[] = [
{
icon: 'far fa-copy', title: 'Newly Added Processes'
},
{
icon: 'far fa-copy', title: 'Terminated Processes'
},
{
icon: 'far fa-copy', title: 'Test Processes'
},
{
icon: 'far fa-copy', title: 'Test Processes'
}
];
这是 component.ts 文件。
export class SecondaryNavigationComponent implements OnInit {
public navItems: any[];
constructor() { }
ngOnInit() {
this.navItems = Items.filter(navItem => navItem);
}
}
有人能告诉我实现此目标的最佳方法吗?
最佳答案
为了让它在同一组件中工作,您可以使用订阅,以便在路由更改时触发,如下所示:
ngOnInit() {
this.route.paramMap.subscribe(params => {
this.animal = params.get("animal")
})
}
关于angular - 根据 Angular 中的路由刷新组件数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62630471/