html:
<table>
<tbody>
<tr ng-repeat="row in Rows track by $index" ng-init="initUserDecision(row,$index)" >
<td>{{employeeName}}</td>
</tr>
</table>
<button id="change"/>
控制器:
$scope.initUserDecision = function(row,index){
$scope.employeeName=row["name"];
}
$scope.rows=[{id:1,name:'siva'},{id:2,name:'ram'}]
//changing $scope.rows in button click event and used $scope.$apply as well
angular.element(document).on("click", "#change", function () {
$scope.rows=[{id:1,name:'ravi'},{id:2,name:'raj'}]
$scope.$apply();
});
ng-init
tr 初始化时第一次调用的函数。如果我单击更改按钮行集合被更改并且它不会ng-init
再次调用。$index
ng-init
如果我通过两次调用来删除轨道。当我使用 track by$index
它时,它只被调用了一次。为什么会这样?关于这个的任何想法。