我在我的HTML页面下面的代码:角和HTML /检查元素脏
<input type="text" name="dns" class="form-control ng-valid" ng-model="conf['dns']" ng-list="">
当我输入文本字段的东西,它改为:
<input type="text" name="dns" class="form-control ng-valid ng-dirty" ng-model="conf['dns']" ng-list="">
我希望检查该领域是否肮脏,并且如果是这样的话,可以采取一些行动。我有以下几点:
Controller.controller('CuController',
function($scope, $location, $modal, Controller) {
console.log($scope.conf['dns']) //prints the value of this field
// Wish to check if $scope.conf['dns'] is dirty
})
我尝试使用$scope.conf[dns].$dirty
,但它返回undefined
。
如何检查字段是否脏(意思是字段的值已更改)?
什么是脏的元素? –
@RajaprabhuAravindasamy:值已更改的字段 – MiddleWare
每次更改角度变量的值时,都可以使用$ watch来查看。 – AleOtero93