如何深度觀察angularjs中的數(shù)組?我的范圍中有一個對象數(shù)組,我想要觀察每個對象的所有值。這是我的代碼:function TodoCtrl($scope) {
$scope.columns = [
{ field:'title', displayName: 'TITLE'},
{ field: 'content', displayName: 'CONTENT' }
];
$scope.$watch('columns', function(newVal) {
alert('columns changed');
});}但是當(dāng)我修改值時,例如我TITLE改為TITLE2,alert('columns changed')從不彈出。如何深入觀察數(shù)組內(nèi)的對象?有一個現(xiàn)場演示:http://jsfiddle.net/SYx9b/
3 回答

拉風(fēng)的咖菲貓
TA貢獻1995條經(jīng)驗 獲得超2個贊
$scope.changePass = function(data){ if(data.txtNewConfirmPassword !== data.txtNewPassword){ $scope.confirmStatus = true; }else{ $scope.confirmStatus = false; }};
<form class="list" name="myForm"> <label class="item item-input"> <input type="password" placeholder="???????????????????" ng-model="data.txtCurrentPassword" maxlength="5" required> </label> <label class="item item-input"> <input type="password" placeholder="???????????????" ng-model="data.txtNewPassword" maxlength="5" ng-minlength="5" name="checknawPassword" ng-change="changePass(data)" required> </label> <label class="item item-input"> <input type="password" placeholder="????????????????????????" ng-model="data.txtNewConfirmPassword" maxlength="5" ng-minlength="5" name="checkConfirmPassword" ng-change="changePass(data)" required> </label> <div class="spacer" style="width: 300px; height: 5px;"></div> <span style="color:red" ng-show="myForm.checknawPassword.$error.minlength || myForm.checkConfirmPassword.$error.minlength">??????????????????? 5 ????</span><br> <span ng-show="confirmStatus" style="color:red">?????????????????????</span> <br> <button class="button button-positive button-block" ng-click="saveChangePass(data)" ng-disabled="myForm.$invalid || confirmStatus">???????</button> </form>
- 3 回答
- 0 關(guān)注
- 603 瀏覽
添加回答
舉報
0/150
提交
取消