Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How can I conditionally add an element attribute eg the checked of a checkbox?

(我如何能有条件地添加元素属性,例如checked复选框的?)

Previous versions of Angular had NgAttr and I think NgChecked which all seem to provide the functionality that I'm after.

(以前的Angular版本具有NgAttr ,我认为NgChecked似乎都提供了我所追求的功能。)

However, these attributes do not appear to exist in Angular 2 and I see no other way of providing this functionality.

(但是,这些属性在Angular 2中似乎不存在,我看不到提供此功能的其他方法。)

  ask by Jonathan Miles translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
399 views
Welcome To Ask or Share your Answers For Others

1 Answer

null removes it:

(null将其删除:)

[attr.checked]="value ? '' : null"

or

(要么)

[attr.checked]="value ? 'checked' : null"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...