Prevent input from setting form $dirty angularjs

前端 未结 7 1436
天涯浪人
天涯浪人 2021-02-07 05:37

I have an ng form on a page. Inside the form I have several controls which need to display a save dialog when the form is dirty, ie form.$dirty = true. However there are some na

相关标签:
7条回答
  • 2021-02-07 06:36

    This is my final answer. Basically angular internally calls the $setDirty() function of the NgModelController when the input is interacted with, so just override that!

    app.directive('noDirtyCheck', function() {
      return {
        restrict: 'A',
        require: 'ngModel',
        link: postLink
      };
      function postLink(scope, iElem, iAttrs, ngModelCtrl) {
        ngModelCtrl.$setDirty = angular.noop;
      }
    })
    
    0 讨论(0)
提交回复
热议问题