【发布时间】:2016-06-22 20:28:21
【问题描述】:
我从 RC1 更新到 RC2 并收到这条神秘消息 - “表达式在检查后已更改”。代码很简单。
父组件有两个孩子“姐妹”和“兄弟”。在初始化之后,姐姐发出一个分配给父变量的事件,而弟弟的Input() 属性绑定到同一个变量。我认为这是使用父变量的兄弟组件之间的“经典”通信。
它曾经在 RC1 中工作,但不是 RC2。我检查了 CHANGELOG.md,但没有发现任何线索。我究竟做错了什么?
http://plnkr.co/edit/HMPAbImpWWeZrVjHyb6H?p=preview
import { Component, Input, Output, EventEmitter } from '@angular/core';
@Component({
selector: 'brother',
template:'<h2>Brother has {{present}}</h2>'
})
export class Brother{
@Input() present: string;
}
@Component({
selector: 'sister',
template:'<h2>Sister has {{_present}}</h2>'
})
export class Sister{
@Output() present: EventEmitter<string> = new EventEmitter;
public _present: string = 'something';
ngOnInit(){
this.present.emit(this._present);
}
}
@Component({
selector: 'my-app',
template: `
<div class="container">
<h2>Parent has {{present}}</h2>
<brother [present]="present"></brother>
<sister (present)="present=$event"></sister>
</div>
`,
directives:[Brother,Sister]
})
export class AppComponent {
public present: string;
}
【问题讨论】:
标签: angular