admin管理员组文章数量:1289412
say I have this div in a ng-repeat
clause:
<div ng-repeat="item in list" class="myDiv" ng-click="doStuff(item)">
{{item.title}}
</div>
And it's based on this model:
$scope.list = [
{ 'title': 'Item 1', 'someData': 'lalala' },
{ 'title': 'Item 2', 'someData': '666' },
{ 'title': 'Item 3', 'someData': 'qwerty' }
];
Then I would end up getting 3 repeated divs.
Now I have an external script analyzing the page and I want to extract the data of the elements.
So for example if I select the first div var div1 = $('div.myDiv:first')
I can get the attributes ng-click
and ng-repeat
from it. I can also use angular.element(div1).data('$binding')
to get the binding {{item.title}}
.
But what I really want is the individual item data of this particular div: i.e. I want to write a function getItemData(element)
that will get div1
and return { 'title': 'Item 1', 'someData': 'lalala' }
.
How can this be done?
Please note that I need a solution that would work both with repeater binding and with regular binding. I basically need to know the actual data that is bound to each element.
say I have this div in a ng-repeat
clause:
<div ng-repeat="item in list" class="myDiv" ng-click="doStuff(item)">
{{item.title}}
</div>
And it's based on this model:
$scope.list = [
{ 'title': 'Item 1', 'someData': 'lalala' },
{ 'title': 'Item 2', 'someData': '666' },
{ 'title': 'Item 3', 'someData': 'qwerty' }
];
Then I would end up getting 3 repeated divs.
Now I have an external script analyzing the page and I want to extract the data of the elements.
So for example if I select the first div var div1 = $('div.myDiv:first')
I can get the attributes ng-click
and ng-repeat
from it. I can also use angular.element(div1).data('$binding')
to get the binding {{item.title}}
.
But what I really want is the individual item data of this particular div: i.e. I want to write a function getItemData(element)
that will get div1
and return { 'title': 'Item 1', 'someData': 'lalala' }
.
How can this be done?
Please note that I need a solution that would work both with repeater binding and with regular binding. I basically need to know the actual data that is bound to each element.
- With an external script analyzing the page how can only get what you find in the page. So 'someDate' would not be available if not contained in the page, like in your example. Jquery should do the job. – dec Commented Apr 5, 2015 at 7:18
1 Answer
Reset to default 10You can access element data object using angular.element.scope
method:
var div1 = $('div.myDiv:first');
var dataItem = angular.element(div1).scope().item;
Demo: http://plnkr.co/edit/MzQRjdgqIpbe9LGrwMDZ?p=preview
本文标签: javascriptGet binding value of element in angularStack Overflow
版权声明:本文标题:javascript - Get binding value of element in angular - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741415735a2377498.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论