小编Cla*_*Ang的帖子

在Angular 2中鼠标悬停之前,组件变量更改未在视图中更新

从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)

javascript ckeditor angular

6
推荐指数
1
解决办法
3434
查看次数

标签 统计

angular ×1

ckeditor ×1

javascript ×1