admin管理员组文章数量:1289507
I have the following code in my HTML page:
<input type="text" name="dns" class="form-control ng-valid" ng-model="conf['dns']" ng-list="">
When I type something in the text field, its changed to:
<input type="text" name="dns" class="form-control ng-valid ng-dirty" ng-model="conf['dns']" ng-list="">
I wish to check if the field its dirty, and do some acts if so. I have the following:
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
})
I try to use $scope.conf[dns].$dirty
, but it returns undefined
.
How can I check if the field is dirty (Meaning that the value of the field was changed)?
I have the following code in my HTML page:
<input type="text" name="dns" class="form-control ng-valid" ng-model="conf['dns']" ng-list="">
When I type something in the text field, its changed to:
<input type="text" name="dns" class="form-control ng-valid ng-dirty" ng-model="conf['dns']" ng-list="">
I wish to check if the field its dirty, and do some acts if so. I have the following:
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
})
I try to use $scope.conf[dns].$dirty
, but it returns undefined
.
How can I check if the field is dirty (Meaning that the value of the field was changed)?
Share Improve this question edited Mar 8, 2016 at 15:22 MIDE11 asked Mar 8, 2016 at 15:21 MIDE11MIDE11 3,5507 gold badges39 silver badges57 bronze badges 4- what is a dirty element? – Rajaprabhu Aravindasamy Commented Mar 8, 2016 at 15:22
- @RajaprabhuAravindasamy: A field that it's value was changed – MIDE11 Commented Mar 8, 2016 at 15:23
- You can use $watch to see every time a value of an Angular variable is changed. – AleOtero93 Commented Mar 8, 2016 at 15:25
- Is this in a form? If in a form use the formName object – charlietfl Commented Mar 8, 2016 at 15:25
2 Answers
Reset to default 5$dirty is a parameter of the input of your form, try $scope.yourForm.dns.$dirty
You can access form properties through the form name like so:
$scope.myForm.dns.$dirty; // boolean
本文标签: javascriptAngular amp HTMLcheck if element is dirtyStack Overflow
版权声明:本文标题:javascript - Angular & HTMLcheck if element is dirty - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741389926a2376043.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论