How to pass data from parent to child component in Angular 4

后端 未结 4 1781
一个人的身影
一个人的身影 2021-02-01 04:10

When I try to pass data from parent to child component. I\'m getting undefined message in the console. Data is in the form of array.

parent.component.html

4条回答
  •  梦如初夏
    2021-02-01 04:46

    With the help of Input() we can pass data

    Child.html

    
    

    chart.component.ts

    @Input() userDetails: any = [];
    
    ngOnInit() {
        console.log(this.userDetails); // as per angular Lifecycle use the ngOnInit for initializing input values
    }
    

提交回复
热议问题