如何改变一个变量的值或在从一个子组件父组件使用的方法,而不使用输入和输出角2子参照可变进父
我尝试这样的事情,但不工作。
@Component({
selector: 'child',
template: `
<div>
<h2>{{name}}</h2>
<button (click) = "rename()" > Rename Parent </button>
</div>
`,
})
export class Child {
name:string;
constructor() {
this.name = 'child'
}
rename() {
App.name = 'Rename';
}
}
@Component({
selector: 'my-app',
template: `
<div>
<h2>Hello {{name}}</h2>
</div>
<child> </child>
`,
})
export class App {
name:string;
constructor() {
this.name = 'Angular2'
}
}
例如这里
的可能的复制[Angular2:父母与孩子的组件通信](http://stackoverflow.com/questions/36316896/angular2-parent-and-child-components-communication) – Fiddles