如何在每次ng-repeat中自动调用控制器功能?我可以使用它吗?
角度观点:
<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);
};
答案 0 :(得分:4)
<div ng-controller="Grid">
<div ng-repeat="a in b">
<p ng-init="method($index)"></p>
</div>
</div>
这样你就可以为每次迭代调用方法..