I have parent component that will send the value to child component from get property. Value that is sent to child component is shown in the same parent HTML page but it is not reachable to child component.
Tried using new method, tried all the lifecycle to fetch the value from the parent component nothing was helpful, also i tried using Viewchild to some extent but neither that helped me to get the value.
parent.component.ts
get name(): string {
return this.service.name.toLocaleLowerCase(); // returns the name Eg: Tom
}
parent.component.html
<child [name]="name"></child>
name::: {{name}} <!--display name as Tom in the parent HTML-->
child.component.ts
@Input() name: string;
constructor() {
console.log(name); // logs unknown
}
The above console.log displays as unknown
i tried to console.log inside ngOnInit method - it displays unknown i tried using ngOnChanges(changes: SimpleChanges) - but for some reason the value is not getting printed first time but second time it gets printed which is not useful. Can anyone please suggest?
i need to fetch the input value inside contructor method.
input
values inside a constructor. – Avin Kavish