1
他のコンポーネントからコンポーネントのプロパティを変更/更新しようとしています。ビューを更新しない他のコンポーネントからプロパティ値を変更します。angular2
プロパティは新しいパラメータに設定されていますが、ビューは更新されていません。
import { Component, Input} from '@angular/core';
@Component({
selector: 'app-home',
template: '<h2 [innerHTML]="title"></h2>'
})
export class TitleComponent {
private title: string = "Initial Title";
setTitle(param) {
this.title = param;
}
}
appcomponent.ts
import { Component} from '@angular/core';
import {TitleComponent} from './seo.title';
@Component({
selector: 'app-header',
template: `<h3>Some text</h3>`,
providers: [TitleComponent]
})
export class AppComponent {
constructor(private updateText: TitleComponent) {
updateText.setTitle("his text is passed to child");
}
}
のsetTitle機能は完全にパラメータを受信し、あまりにもプロパティ(this.title)を更新するが、図で
pagetitle.ts更新されていません。
ネストされたコンポーネントの処理は望ましくありません。私はどこでも利用できるようにプロパティを更新したい。