yaxx
yaxx

Reputation: 655

Accessing data attribute in angularjs

I am trying to access html data attribute within my angular controller but keep getting 'null' returned even though the attribute is actually set dynamically in the html: here is the code:

<button class="btn" ng-data-stuff="{{psn._id}}" ng-click="person.doStuff($event.target)">
   Follow
</button>

self.doStuff = function (e) {
    $window.alert(e.attributes('data-stuff'))
}

Upvotes: 0

Views: 632

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222682

There is nothing named ng-data-stuff attribute in a button, instead you can directly pass the psn value to the button function as follows,

<button class="btn" ng-click="person.doStuff(psn)">Follow </button> 

and inside the function,

self.doStuff = function (e) {
 $window.alert(e._id);
)

Upvotes: 1

Related Questions