【发布时间】:2016-09-06 11:58:20
【问题描述】:
我正在尝试从其他组件修改/更新组件的某些属性。
该属性正在设置为新参数,但它没有更新视图。
pagetitle.ts
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),但视图没有更新。
我不想处理嵌套组件。我想更新属性,以便我可以在任何地方使用。
【问题讨论】: