从 angular 开始,我面临以下困难:我必须将数据从子路由组件传递给父组件。
我以为我可以将 @Output 与 eventEmitter 一起使用。但我觉得不可能 我还尝试使用生成更改检测错误(ExpressionChangedAfterItHasBeenCheckedError)的主题。
子组件的 ts :
ngOnInit(): void {
this.itemsMenu = this.rayonService.itemsMenu;
this.activatedRoute.paramMap.subscribe(params => {
let paramUrlZone = params.get('id');
if (paramUrlZone !== null) {
this.isTest = true; // pass to the parent
}
});
this.initRefForm();
}
html parent(子组件被路由...)
------------------------------------
<div class="router-container">
<router-outlet></router-outlet>
</div>
------------------------------------
我不知道怎么做这些东西.. 感谢您的帮助!
答案 0 :(得分:0)
你可以像这样在父组件中直接订阅子组件的params数据来避免将id传递给父组件:
constructor(route: ActivatedRoute) {
route.firstChild.params.subscribe((params) => {
console.log(params.id);
});
}