luzny
luzny

Reputation: 2400

How to call scope function with data from ng-repeat?

How to call controller function automatically in each ng-repeat? Can I use for it directive?

Angular view:

<div ng-controller="Grid">
    <div class="row" data-ng-repeat="row in rows">
        <div class="col" data-ng-repeat="col in row.col">
            <div dnd-list="column.elements">
                <div ng-repeat="item in column.elements" ng-include="test.html"></div>
            </div>
        </div>
    </div>
</div>

<script type="text/ng-template" id="test.html'">
  <div style:"display: none;">{{item.grid_id = column.grid_id}}</div>
  <div style:"display: none;">{{item.position = $index}}</div>
  <-- {{addItemToArrayAndReorderGridEl(item, column, $index)}} -->
  <-- <div ng-model="addItemToArrayAndReorderGridEl(item, column, $index)" ></div> -->
</script>

Controller snippet:

$scope.items = [];
$scope.addItemToArrayAndReorderGridEl = function (item, column, position) {
  if ($scope.action_type === "edit") {
    $scope.items.push(item);
  }
  console.log($scope.items);
};

Upvotes: 0

Views: 1328

Answers (1)

Ved
Ved

Reputation: 12093

<div ng-controller="Grid">
  <div ng-repeat="a in b">
  <p ng-init="method($index)"></p>
  </div>
</div>

This way you can call method for each iteration..

Upvotes: 4

Related Questions