instance-oom / ngx-markdown-editor

Angular markdown editor based on ace editor
http://lon-yang.github.io/markdown-editor/
Apache License 2.0
174 stars 48 forks source link

Changing model and changing mode causes stale data #62

Closed tank104 closed 4 years ago

tank104 commented 4 years ago

Hi, I think there might be an issue when setting content and then switching to "preview" mode, then back to "editor" mode - the editor text has the old content until you click on editor, or change it.

<button class="btn btn-default btn-primary" *ngIf="this.mode == 'preview'" (click)="editClick()">Edit</button>
<button class="btn btn-default btn-primary" *ngIf="this.mode == 'editor'" (click)="cancelClick()">Cancel</button>

<md-editor name="Content" [(ngModel)]="content" [mode]="mode" [height]="'400px'" [options]="options" required>

ngOnInit(): void { this.content = "123"; }

editClick() { this.mode = "editor"; }

cancelClick() { this.content = "xyz"; this.mode = "preview"; //setTimeout(() => { // this.mode = "preview"; //}, 100); }

If you click edit - it shows "123" then click cancel, then click edit again and it still shows "123" until you click on the editor then changes to "xyz".

If you uncomment the setTimeout then that fixes it.

instance-oom commented 4 years ago

Fixed in 3.1.2

https://stackblitz.com/edit/angular-jvx4of

tank104 commented 4 years ago

Thanks!