Communication data from parent component to child component using @input in angular 2. My purpose is I want to call service in child component using value parameter @input, but the value property is "undefine". this is my child component :
import { Component, OnInit, EventEmitter, Input,Output } from '@angular/core';
@Component({
selector: 'app-child',
templateUrl: './child.component.html'
})
export class ChildComponent implements OnInit {
@Input() productId: any; --> working perfectly if bind into html
constructor() {
}
ngOnInit(): void {
console.log(this.productId) --> undefine?
//in this methode i will call service to fetch another data from database using parameter productId..
}
}
How to solve this?
productIdcome from?ngOnInit()is called. A setter orngOnChangesalso works for data that is set later.ngOnInit()only works for data that is already available when the component is created.