Raiper34 / ngx-simple-text-editor

Ngx Simple Text editor or ST editor is a simple native text editor component for Angular 9+.
https://ngx-simple-text-editor.netlify.app
MIT License
5 stars 1 forks source link

Initial value not working #18

Closed hasanw07 closed 8 months ago

hasanw07 commented 8 months ago

I have tried this code but no value appeared in the st-editor.

In my code, the "objective" is calling from api service inside ngOnInit().

<st-editor formControlName="objectives" [(ngModel)]="objectives" [config]="editorConfig" > {{ objectives }}

Untitled
Raiper34 commented 8 months ago

Hi,

You mixed two concepts together Reactive forms and Template-driven forms. Use Reactive either Template, not both at the same time. I tested it and it works for me with [(ngModel)].

hasanw07 commented 8 months ago

I'm using reactive forms, but it's still cannot load the value. here is my code snippet

ngOnInit():void{ this.testForm = this.fb.group{[ objectives: new FormControl(this.objectives, Validators.nullValidator), ]};

forkJoin({
        testData : this.applicationSvc.getObjectives(this.id)   
    }).subscribe({
        next: (data: any) => {

        this.objectives = data.testData;
        this.testForm.patchValue(this.objectives);
        this.courseForm.get("objectives")?.patchValue(this.objectives);
});

}

html

<st-editor formControlName="objectives" [config]="editorConfig"></st-editor>
Raiper34 commented 8 months ago

Hey man, Thanks for the issue, Reactive forms are really broken. The bug fix will be during the weekend in the latest version.

Raiper34 commented 8 months ago

I found bug and I am fixing, but If you need it urgent, you can use something like

setTimeout(() => this.testForm.patchValue(this.objectives))
Raiper34 commented 8 months ago

Released in v4.0.3, versions compatible with older Angular will be released soon.

Raiper34 commented 2 weeks ago

Also fixed in v1.4.1 v2.0.1 and v3.0.1