How to capture the @Input() parameter in the child component controller class. I tried to console log it from Constructor and OnInit life cycle event, but it comes as undefined. But id gets properly displayed on the child component html with one way binding
I needed the parameter info to write some custom logic in my child component.
parent.component.ts
@Component({
selector: 'app-parent',
templateUrl: './parent.component.html'
})
export class ParentComponent implements OnInit {
parameter : any = [1 ,2, 3] ;
}
child.component.ts
@Component({
selector: 'app-child',
templateUrl: './child.component.html'
})
export class ChildComponent implements OnInit {
@Input() parameter : any ;
Constructor() {
console.log(this.parameter) // prints undefined
}
ngOnInit() {
console.log(this.parameter) // prints undefined
}
}
parent.component.html
<app-child [parameter]='parameter' ></app-child>
child.component.html
{{ parameter }} // prints [1 ,2, 3]