0

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'))
}
2
  • post your html code Commented Jan 3, 2018 at 2:19
  • <button class="btn" ng-data-stuff="{{psn._id}}" ng-click="person.doStuff($event.target)">Follow </button> Commented Jan 3, 2018 at 2:23

1 Answer 1

1

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);
)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.