Mithun Shreevatsa
Mithun Shreevatsa

Reputation: 3599

How to ng-bind on html data attributes and placeholders?

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

Answers (1)

Sam Willis
Sam Willis

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

Related Questions