从angular2-alpha更新到最新版本后,布尔值的更改不会更新*ngIf,直到执行某些操作.
这是有问题的组件:
declare var CKEDITOR: any;
export class FieldComponent {
@Input() field: any = {};
ckeditor: any;
editable: boolean = false;
constructor(){
this.switchToUnEditable();
this.listenForEvent("FieldEditableEvent", (data) => {
this.switchToEditable();
});
}
switchToEditable(){
this.ckeditor.destroy();
this.ckeditor = CKEDITOR.replace(this.field.id);
this.editable = true;
}
switchToUnEditable() {
if(this.ckeditor) {
this.ckeditor.destroy();
}
this.ckeditor = CKEDITOR.replace(this.field.id, {
toolbar: []
})
this.editable = false;
}
}
Run Code Online (Sandbox Code Playgroud)
以下是此组件的模板:
<div *ngIf="editable" class="green-background white-text unlocked">
This field is unlocked!
<button (click)="switchToUnEditable()">
Save and close.
</button>
</div>
<div *ngIf="!editable" class="red-background white-text locked">
This …Run Code Online (Sandbox Code Playgroud)