Angular 2.0コンポーネントを作成するとき、プロパティのデフォルト値をどのように設定しますか?
たとえば、デフォルトでに設定fooしたいの'bar'ですが、バインディングがすぐにに解決される場合があります'baz'。これはライフサイクルフックでどのように機能しますか?
@Component({
selector: 'foo-component'
})
export class FooComponent {
@Input()
foo: string = 'bar';
@Input()
zalgo: string;
ngOnChanges(changes){
console.log(this.foo);
console.log(changes.foo ? changes.foo.previousValue : undefined);
console.log(changes.foo ? changes.foo.currentValue : undefined);
}
}
以下のテンプレートを考えると、これが私が期待する値です。私が間違っている?
<foo-component [foo] = 'baz'></foo-component>
コンソールに記録:
'baz'
'bar'
'baz'
<foo-component [zalgo] = 'released'></foo-component>
コンソールに記録:
'bar'
undefined
undefined