“我的父母”页面如下所示。
html:
<counter [conversationId]="conversationId"></counter>
组件:
public conversationId: string;
public showModal() {
this.conversationId = '1234'
this.modalService.showComponent(CounterPage, { class: 'modal-lg' });
}
“我的孩子”页面看起来像这样。
@Input() conversationId: any;
public ngOnInit (): void {
alert(this.conversationId); //shows undefinded.
}
看起来这是常见的问题here。没有一种解决方案对我有用。
答案 0 :(得分:0)
这些参数在ngAfterContentInit()方法之前接收值。
在此图像中查看角度的生命周期:https://v2.angular.io/resources/images/devguide/lifecycle-hooks/hooks-in-sequence.png
尝试:
@Input() conversationId: any;
public ngAfterContentInit (): void {
alert(this.conversationId); //shows undefinded.
}