Angular 2 - Passing data to Child component after Parent initialisation

后端 未结 5 2043
花落未央
花落未央 2020-12-23 16:58

I have a parent component which is getting data from a server through a service. I need some of this data to be passed to the Child component.

I\'ve been trying to p

5条回答
  •  盖世英雄少女心
    2020-12-23 17:20

    @Component({
        selector: 'test-child',
        template: `
            
        `
    })
    
    export class ChildComponent implements OnChanges {
        @Input() childData: any;
    
        ngOnChanges() {
            console.log(childData); // logs undefined
        }
    }
    

    This is supposed to be like this, no? I hope this might be the problem.

        ngOnChanges() {
            console.log(this.childData); // reference with this
        }
    

提交回复
热议问题