I've searched the web but can't find a way to work with contenteditable
events on Angular 6/7. Angular seems to have a messy solution with it but said feature doesn't seem to be carried over to recent versions.
A use case would be is on a content editable onChange
event, call a function:
<div contententeditable="true" [change]="onNameChange(if.there.is.such.a.thing)">Type your name</div>
...
private name: string;
onNameChange(name) {
this.name = name;
}
Any ideas on this? Thanks.
Angular does not have an accessor for contenteditable , so if you want to use it with forms you will have to write one.
The contenteditable attribute specifies whether the content of an element is editable or not.
The contenteditable is used to specify whether the element's content is editable by the user or not. Syntax: <element contenteditable="true|false"> This attribute has two values. true: If the value of the contenteditable attribute is set to true then the element is editable.
You can set the HTML5 contenteditable attribute with the value true (i.e. contentEditable="true" ) to make an element editable in HTML, such as <div> or <p> element.
You can use the input
event, like so:
<div contenteditable (input)="onNameChange($event.target.innerHTML)">
Type your name
</div>
Here is a Stackblitz demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With