@Input property is undefined in Angular 2's onInit

后端 未结 4 650
天命终不由人
天命终不由人 2020-12-05 09:39

Trying to get the component\'s @Input value in constructor or ngOnInit. But it is coming as undefined all the time.

<
4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-05 10:05

    In the ngOninit method use,

    ngOnInit() {
        if(this.hero) 
            console.log('hero', this.hero);
    }
    

提交回复
热议问题