[SOLVED] How can I append HTML format value to normal format in angular using CKEditor

Issue

I am using angular CKEditor for HTML textarea. So I just get the value from CKEditor and show it to some other div. I have integrated this function using ngModel but I can’t show the HTML form value. It’s show the raw HTML value. Please check the below code and output.

HTML

<div class="row">
        <div class="col-md-6 col-lg-6 col-sm-12 text-center">
            <div class="bg-gray p-5 m-3" *ngIf="!editorStatus">
                <p class="mb-0">{{ htmlEditorValue }}</p>
            </div>

            <div class="htmleditor" *ngIf="editorStatus">
                <ckeditor name="htmlEditor" [config]="config" [editor]="Editor" [(ngModel)]="htmlEditorValue" skin="moono-lisa" language="en">
                </ckeditor>
                <button class="btn trans-btn list-head-btn ng-star-inserted btn-gradient mt-3 w-25" (click)="getEditorValue()">Save</button>
            </div>
        </div>
    </div>

TS

editorStatus: boolean = false;
htmlEditorValue = 'Test';

    changeEditor() {
        this.editorStatus = true;
      }
      
      getEditorValue() {
        this.editorStatus = false;
        console.log("ashok"+this.htmlEditorValue);
      }

And my output is:
enter image description here

I recive a Raw HTML but i want HTML format. Anyone help me to fix this issue

Solution

Try setting your htmlEditorValue in .html file like this:

<p class="mb-0" [innerHtml]="htmlEditorValue"></p>

Take a look here, if I understand your problem the right way, it should solve the problem: https://stackblitz.com/edit/angular-ivy-k7deuo?file=src%2Fapp%2Fapp.component.ts

Answered By – devZ

Answer Checked By – David Goodson (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *