Why input properties on component are not available in constructor
@Input() results: Result[];
constructor() {
console.log(this.results); // why it is not available here
}
Why input properties on component are not available in constructor
@Input() results: Result[];
constructor() {
console.log(this.results); // why it is not available here
}
Input property isn't initialized until view is set up so generally you can access input value on ngOnInit()
check LifeCycle. https://angular.io/docs/ts/latest/guide/lifecycle-hooks.html
import {Component, Input} from 'angular2/angular2'
@Component({
selector: 'child',
template: `
<p>The next number is {{ mynumber + 1 }}</p>
`
})
class ChildComponent {
@Input() mynumber: number;
ngOnInit(){
console.log(this.number);
}
}
@Component({
selector: 'parent',
template: `
<child [mynumber]="41"></child>
`
})
export class ParentComponent {}