I have a component parent that calls another component child with an input-property.
The property is available in the childs template but not in the constructor or OnInit. Thats normal behaviour or am I doing something wrong?
parent.component.ts
import {Component} from '@angular/core';
@Component({
selector: "parent",
template: `<child [name]="'foobar'"></child>`
})
export class ParentComponent
{
}
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);
}
}
Change
console.log ("oninit: " + name);
to
console.log ("oninit: " + this.name);