I am encountering an issue where a component parent is calling another component child with an input-property.
Although the property is available in the child's template, it does not seem to be accessible within the constructor or OnInit functions. Is this normal behavior, or have I made an error in my implementation?
parent.component.ts
import {Component} from '@angular/core';
@Component({
selector: "parent",
template: `<child [name]="'foobar'"></child>`
})
export class ParentComponent
{
}
child.component.ts
import {Component, Input, OnInit} from '@angular/core';
@Component({
selector: "child",
template: "name={{ name }}"
})
export class ChildComponent
{
@Input () name:string="init";
constructor ()
{
console.log ("constr: " + name);
}
ngOnInit ()
{
console.log ("oninit: " + name);
}
}
EDIT
Updated my sample code and placed @Input inside the class.
Revised my example to real code. While the template displays "foobar", the console output shows an empty string.