Reputation: 26467
I've got an input that I either want to have custom data-error
attribute present:
<input data-error>
or not:
<input>
Let's say I've got an boolean error
variable available on the scope, which is to define whether to display the attribute or not. How should I do that in angular?
I tried some combinations with setting ng-attr-data-error
but I didn't manage to get expected result.
Upvotes: 1
Views: 103
Reputation: 19823
use
<input ng-attr-data-error="{{error && 'when-error-true' || undefined }}">
It adds data-error
attribute (with value when-error-true
) when error
is true
otherwise it removes the data-error attribute.
Upvotes: 1