我有这个指令,可以避免将输入标记为$pristine
:
(function () {
'use strict';
angular
.module('blocks.noDirtyCheck', [])
.directive('noDirtyCheck', function() {
// Interacting with input elements having this directive won't cause the
// form to be marked dirty.
return {
restrict: 'A',
//require: 'ngModel',
link: function(scope, elm, attrs, ctrl) {
ctrl.$pristine = false;
}
};
});
})();
和另一个定义自定义窗口小部件的窗口<workflow-input>
:
(function () {
'use strict';
angular
.module('app.widgets')
.directive('workflowInput', workflowInput)
.controller('WorkflowInputController', WorkflowInputController);
/* @ngInject */
function workflowInput() {
return {
restrict: 'E',
scope: {
selectedWorkflow: '=ngModel'
},
controller: WorkflowInputController,
controllerAs: 'vm',
templateUrl: '/client/app/widgets/workflowInput.html'
};
}
...
})();
我想用它作为:
<workflow-input ng-model="vm.asset.workflows" no-dirty-check></workflow-input>
我理解noDirtyCheck
指令不完整,因为它没有直接应用于实际的<input>
并且需要修复,但这不是问题,问题是永远不会调用noDirtyCheck
指令。我在workflowInput
控制器上放了一个断点,我可以看到该指令没有列在controllerDirectives
中nodeLinkFn
的元素中(在angular的代码库中)。那里只有ngModel
和workflowInput
。
任何人都知道为什么会发生这种情况?谢谢