Angular access to bound element

angularjs, javascript

Solution

I added an id to the div "item-{{ $index }}", so i could fetch it by id from my loop. Doesn't feel very "angular", but it worked!

<div id="item-{{ $index }}" class="block" ty-stacked-block ng-repeat="item in items" ng-style="{ 'top' : item.top+'px', 'left' : item.left+'px' }">
  <a href="{{ item.url }}" title="{{ item.title }}">
    <img ng-src="{{ item.src }}" alt="{{ item.title }}" />
  </a>
  <br />
  <p>{{ item.title }}</p>
</div>

Problem

It may be an issue in the way i'm architecting my application, but i keep running into the need to be able to access the dom element via my items array: ``` $scope.items = [{"src": src, "url": url, "title": title, "top": 0, "left": -500 }]; ``` Bound to html with: ``` <div class="block" ty-stacked-block ng-repeat="item in items" ng-style="{ 'top' : item.top+'px', 'left' : item.left+'px' }"> <a href="{{ item.url }}" title="{{ item.title }}"> <img ng-src="{{ item.src }}" alt="{{ item.title }}" /> </a> <br /> <p>{{ item.title }}</p> </div> ``` Basically I have another piece of code that wants to run through $scope.items and make changes to the div's positioning (based on each div's height). ``` scope.repositionItems = function() { _.each(scope.items, function(item) { // TODO get item's height somehow }); }; ```

Original source