Jonathan Miles Jonathan Miles - 8 months ago 80
AngularJS Question

How to add conditional attribute in Angular 2?

How can I conditionally add an element attribute e.g. the

of a checkbox?

Previous versions of Angular had
and I think
which all seem to provide the functionality that I'm after. However, these attributes do not appear to exist in Angular 2 and I see no other way of providing this functionality.

Answer Source

null removes it:

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