Reputation: 2052
I want to bind the value of variable to input after the ngOnInit
but in my case it is binding to the default value that is initialised before.
@Component({
selector: 'myapp',
template: `{{test}} `
})
class App {
@Input() test;
}
@Component({
selector: 'parent',
directives: [App],
template: `
<myapp [test]="test"></myapp>
`
})
export class parent implements OnInit{
test:string='i dont want this value';
ngOnInit() {
this.test="I am after ngOninit";
}
}
I want "I am after ngOnInit" to be printed but in my case it is "i dont want this value" is printed. Here is the plunker code : http://plnkr.co/edit/c4wR1X740wtHaFjvuPXW?p=preview How can i achieve this. Thank you.
Upvotes: 2
Views: 590
Reputation: 40677
Updated as OP said it should be a 2.4.1 version plunker: http://plnkr.co/edit/TLj9Ta4rv64Esi2uFwTP?p=preview
Your ngOnInit
function is never called.
Since you are using the alpha version of angular2, lifecycle hook names are different.
onInit() {
this.test="I am after ngOninit";
}
Plunker: http://plnkr.co/edit/eDs2hjNydBoQBYWaKUZN?p=preview
Alpha.47 Breaking Changes: https://github.com/angular/angular/blob/master/CHANGELOG.md#breaking-changes-24
Upvotes: 2