Can not patchValue of PrimeNG p-editor component

Discussão em 'Angular' iniciado por Mofiro Jean, Novembro 29, 2024.

  1. Mofiro Jean

    Mofiro Jean Guest

    I created a form that makes use of p-editor element to write rich formatted text, but i ran into a problem, the editor creates and submits the rich text, but when we want to update the form with a value from the server, using the angular reactive form patchValue method doesn't update the editor as required. Here is my code

    Template:

    <form>
    <div class="col-12 my-3">
    <label class="small font-bold" for="content" i18n>Requirments</label>
    <p-editor formControlName="content" id="content" placeholder="content..." [style]="{ height: '200px' }"></p-editor>
    </div>
    </form>


    component:

    export class SampleComponent implements OnChanges {

    @Input() data?: {content: string};
    formEditor: FormGroup

    constructor(
    private _fb: FormBuilder,
    )
    {
    this.formEditor = this._fb.group({
    content: ["", Validators.required]
    })
    }

    ngOnChanges() {
    // I verified and indeed the data comes when there is a change
    if (this.data) {
    this.patchEditorForm(this.data);
    }
    }

    private patchEditorForm = (data: {content: string}) => {
    this.formEditor.patchValue({
    content: post.content
    })
    }

    }


    I use the AfterViewInit and Angular @ViewChild decorator but it didn't still work

    Continue reading...

Compartilhe esta Página