Reputation: 1227
I wonder if there is a way in angularjs to add or remove attributes according to condition. for example, instead of writing something like this
<div ng-if="isClickable" ng-click="clicked()">This is my button</div>
<div ng-if="!isClickable"> this is my button</div>
I will be able to write something, maybe, like this:
<div ng-click="clicked()" ng-attrs="{'ng-click': isClickable}">
Upvotes: 0
Views: 76
Reputation: 136184
You can't remove attribute using any angular directive (you can do this via writing your own custom directive). Rather you can convert such div
's into button
and use ng-disabled
<button ng-disabled="!isClickable" ng-click="clicked()">This is my button</button>
Or you can use way suggested by @JBNizet
<div ng-click="isClickable && clicked()">This is my button</div>
Upvotes: 2