Skip to content

Commit 426e836

Browse files
authored
fix(ngx-jodit-pro): value not changing on reactive form
Merge pull request #36 from Duke-of-Karamel/fix/Jodit-pro-reactive-forms-value-not-changing
2 parents 0737d00 + 3ff4376 commit 426e836

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

libs/ngx-jodit-pro/src/lib/ngx-jodit-pro.component.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class NgxJoditProComponent implements ControlValueAccessor, AfterViewInit
4747
this._options = value;
4848

4949
if (value) {
50-
this.initJoditContainer();
50+
this.initJoditContainer().then();
5151
}
5252
}
5353

@@ -105,8 +105,8 @@ export class NgxJoditProComponent implements ControlValueAccessor, AfterViewInit
105105
// Prevent ExpressionChangedAfterItHasBeenCheckedError
106106
delay(0)
107107
).subscribe(([[_, initialized], text]) => {
108-
if (this.joditContainer?.nativeElement && initialized) {
109-
this.joditContainer.nativeElement.innerHTML = text;
108+
if (this.jodit && initialized) {
109+
this.jodit.setEditorValue(text);
110110
}
111111
});
112112
}
@@ -122,23 +122,24 @@ export class NgxJoditProComponent implements ControlValueAccessor, AfterViewInit
122122
);
123123
}
124124

125-
ngAfterViewInit() {
126-
this.initJoditContainer();
125+
async ngAfterViewInit() {
126+
await this.initJoditContainer();
127127
}
128128

129129
ngOnDestroy() {
130130
this.valueSubscription?.unsubscribe();
131131
this.jodit?.events.destruct();
132132
}
133133

134-
initJoditContainer() {
134+
async initJoditContainer() {
135135
if (this.joditContainer?.nativeElement) {
136136
if (this.jodit) {
137137
this.jodit.destruct();
138138
this.joditInitializedSubject.next(false);
139139
}
140140
this.jodit = Jodit.make(this.joditContainer.nativeElement, this._options) as IJodit;
141-
this.joditContainer.nativeElement.innerHTML = this.valueSubject.getValue();
141+
await this.jodit.waitForReady();
142+
this.jodit.setEditorValue(this.valueSubject.getValue());
142143

143144
this.jodit.events.on('change', (text: string) => {
144145
this.internValueChange = true;

0 commit comments

Comments
 (0)