Acessando os dados transmitidos usando o decorador @Input
Eu tenho um componente filho que se parece com isso
Componente filho
@Component({
selector: 'child-component',
//TemplateUrl, Styles and Providers
})
export Class ChildComponent implements OnInit{
@Input()
arrayToGet; //An array that I want to pass from Parent to child
ngOnInit(){
console.log('The Array I got is ', this.arrayToGet); //Undefined, Tried even with setTimeout
}
//A bunch of methods to work with the array I get
}
Componente pai
@Component({
selector: 'parent-component',
template: '<div>
<child-component [arrayToGet]="models"></child-component>
</div>',
//A bunch of Styles and Providers
})
export class ParentComponent{
models;
constructor(......){}
ngOnInit(){
//Get an array from a service assign to this.models;
}
}
O problema é que não consigo executar nenhuma operação noarrayToGet
dentro do meuChildComponent
. No entanto, eu posso usar as propriedades emarrayToGet
dentro do meuChildComponent
HTML.
Alguma ideia?