简体   繁体   English

无法访问NgOnInit -Angular 6中的输入属性

[英]Unable to access Input Property in NgOnInit -Angular 6

My Parent page looks like this. 我的父页面看起来像这样。

html: HTML:

<counter  [conversationId]="conversationId"></counter>

component: 零件:

public conversationId: string;

public showModal() {   
 this.conversationId = '1234'
 this.modalService.showComponent(CounterPage, { class: 'modal-lg' }); 
}

My Child page looks like this. 我的孩子页面看起来像这样。

 @Input() conversationId: any;
 public ngOnInit  (): void {
    alert(this.conversationId); //shows undefinded.
  }

Looks like this is common issue here . 看起来这是常见的问题在这里 None of the solutions worked for me. 这些解决方案都不适合我。

The params receive values before the method ngAfterContentInit(). params在方法ngAfterContentInit()之前接收值。

See the lifecycle of angular in this image: https://v2.angular.io/resources/images/devguide/lifecycle-hooks/hooks-in-sequence.png 在此图片中查看角度的生命周期: https//v2.angular.io/resources/images/devguide/lifecycle-hooks/hooks-in-sequence.png

try: 尝试:

@Input() conversationId: any;
 public ngAfterContentInit  (): void {
    alert(this.conversationId); //shows undefinded.
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM