Reputation: 3550
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)?
Upvotes: 4
Views: 8358
Reputation: 25535
You can access form properties through the form name like so:
$scope.myForm.dns.$dirty; // boolean
Upvotes: 4
Reputation: 180
$dirty is a parameter of the input of your form, try $scope.yourForm.dns.$dirty
Upvotes: 5