Search code examples
angularjsangular-ngmodel

angular ng-model don't update on dirty value


i would like to know if it's possible to 'prevent' an update of an form field (input, select....) that it's dirty due to user interaction. If i update the ng-model primitive (ie: set pippo from 1 to X) the input will get updated even if i manually edit the control.

It's possible to prevent that?

demo page:

http://plnkr.co/edit/ClXoS7YVcEDtcApsNpde

the input field count UP every X secs. if i enter "AAA" i would like that update STOP, because the input it's "dirty" due to user interaction.


Solution

  • You can use ngModelController to tell if the input is dirty. https://docs.angularjs.org/api/ng/directive/ngModel

    Modified your plunker to http://plnkr.co/edit/oJMrQZLugnzisqdXScvN?p=preview The update function looks like

    this.update = function() {
        if(!$scope.frmPippo.pippo.$dirty)
          $scope.pippo += 1;
    }