我从RC1升级到RC2后收到了这个神秘的信息 - “Expression has changed after it was checked”。代码非常简单。父组件有两个子组件“sister”和“brother”。在初始化之后,姐姐发出一个事件,该事件被分配给父变量,而兄弟的
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;
}