In Angular 2 how can I make two way data binding with a contenteditable div?
<div class="editable" contenteditable="true">
<h1>Text Field</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In pharetra felis in sem porta feugiat.</p>
</div>
To work properly, it is necessary to implement
ControlValueAccessor
for the directivecontenteditable
. See my solution: ng-contenteditable.Angular 4/2 (Typescript) with dynamic editable:
I've adapted Isetty's answer to work with the release version of Angular 2.0, now it is available. Apart from working with the release version, I've also added a keyup event and used textContent rather than innerText, because that suites my application better. You may wish to change these things.
Please refer this code. It will work you i think.
app.ts
contenteditableModel.ts:
For the extra inputs i found a link for you. https://www.namekdev.net/2016/01/two-way-binding-to-contenteditable-element-in-angular-2/
in angular 2 [(ngModel)] used for two way data binding.
the answer of your question is already here How to use [(ngModel)] on div's contenteditable in angular2? check this out and let me know if it is working for you or not.