Reputation: 733
I am currently using 1.2.x version of AngularJs and I'm trying to retrieve the data
from the HTML element:
<div ng-controller="mycontroller" data-foo="bar1">
<div ng-controller="mycontroller" data-foo="bar2"></div>
I want to retrieve the values of foo
and have a result of [bar1, bar2]
. I thought about using $.data()
, but want to avoid that. The controller mycontroller
is repeated on purpose and is not a mistake. Any advice on how to retrieve the data in the HTML element?
Upvotes: 1
Views: 42
Reputation: 2954
You can access data
attributes within your controller:
app.controller('mycontroller', function ($scope, $attrs) {
console.log($attrs.foo);
});
Upvotes: 2