gautam siva
gautam siva

Reputation: 113

How to use [(ngModel)] and innerHTML on div's contenteditable in angular?

Here's my code :

<div #editor class="editor" 
              style=" max-height: 200px;" 
              (input)="onChange()"
              [(ngModel)]="blogData.description"
              name="description"
              contenteditable></div>

The Error that i am getting:

Error: No value accessor for form control with name: 'description'

How can i use [(ngModel)] as well as innerHTML property on div's contenteditable?

Upvotes: 2

Views: 516

Answers (1)

waterplea
waterplea

Reputation: 3631

You need to write your own ControlValueAccessor to work with contenteditable: https://angular.io/api/forms/ControlValueAccessor

I already did it and released it as opensource package, feel free to use it: https://github.com/TinkoffCreditSystems/angular-contenteditable-accessor https://www.npmjs.com/package/@tinkoff/angular-contenteditable-accessor

It works with all modern browsers, including IE11.

Upvotes: 4

Related Questions