Reputation: 3599
As we know it is good to use ng-bind
instead of {{expression}}
considering performance which is clearly mentioned here
Similar to this, just want to understand how can we bind class
attributes or data
attributes or any other properties which is not related to html display elements?
Ex: We can bind to span
element like: <span ng-bind="vm.bindText"></span>
Where as what if we want to bind for class
without any conditions or using ng-class
and also directives
Now it looks like this:
<span class="{{vm.bindText}}"></span>
And this implementation works for class: <span ng-class="vm.bindText"></span>
But how to do it on custom data attributes like: <input data-id="vm.bindOldId" placeholder="vm.bindText">
instead of <input data-id="{{vm.bindOldId}}" placeholder="{{vm.bindText}}">
Just curious to know about this and does it really makes sense of doing it as well?
Let me know your thoughts on this.
Upvotes: 0
Views: 660
Reputation: 4211
Can't you use ng-class
?
ng-class="vm.bindText"
You can add data attributes like so to:
ng-attr-data-YOUR_ATTRIBUTE="YOUR VALUE"
Upvotes: 1