1

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?

1 Answer 1

2

You can access data attributes within your controller:

app.controller('mycontroller', function ($scope, $attrs) {
    console.log($attrs.foo);
});

Fiddle

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.