javascript - Angular enabledisable contenteditable on div element - Stack Overflow

ProblemI want to bind a boolean to the contenteditable directive to a div which does not work. Output:C

Problem

I want to bind a boolean to the contenteditable directive to a div which does not work.

Output:

Can't bind to 'contenteditable' since it isn't a known property of 'div'.

Tries

  1. I tried to add [] brackets to bind a variable to it. editable is a ponent property type boolean
<div class="text-editor"
     [contenteditable]="editable"></div>
  1. I also tried to add double curly brackets {{}} which leads to the same issue
<div class="text-editor"
     contenteditable="{{editable}}"></div>

It works in this cases

If I simply set the string true without any brackets then it works, but this solution does not solve my requirement since I want to change the behaviour dynamically

<div class="text-editor"
     contenteditable="true"></div>

I couldn't find any solution on questions at SO. I hope you know a solution and can share it with me. Thanks a lot.

Problem

I want to bind a boolean to the contenteditable directive to a div which does not work.

Output:

Can't bind to 'contenteditable' since it isn't a known property of 'div'.

Tries

  1. I tried to add [] brackets to bind a variable to it. editable is a ponent property type boolean
<div class="text-editor"
     [contenteditable]="editable"></div>
  1. I also tried to add double curly brackets {{}} which leads to the same issue
<div class="text-editor"
     contenteditable="{{editable}}"></div>

It works in this cases

If I simply set the string true without any brackets then it works, but this solution does not solve my requirement since I want to change the behaviour dynamically

<div class="text-editor"
     contenteditable="true"></div>

I couldn't find any solution on questions at SO. I hope you know a solution and can share it with me. Thanks a lot.

Share Improve this question asked Feb 12, 2020 at 8:03 Ling VuLing Vu 5,1815 gold badges27 silver badges49 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

Use either [attr.contenteditable]="editable"

or [contentEditable]="editable"

The "attr." prefix will emit an attribute for whatever suffix you use.

<div [attr.contenteditable]="editable">Edit me!</div>

OR

<div [contentEditable]="editable">Edit me!</div>

DEMO: https://stackblitz./edit/angular-xablzf

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744653858a4586062.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信