第二个 AngularJS 指令未从 html 属性加载
Second AngularJS directive not loading from html attribute
我有这个指令避免输入被标记为 $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
控制器上放置了一个断点,我可以看到该指令未在 nodeLinkFn
中元素的 controllerDirectives
中列出(在 angular 的代码库中)。那里只有 ngModel
和 workflowInput
。
有人知道为什么会这样吗?谢谢
我忘记将模块注入应用程序。谢谢@Lex
我有这个指令避免输入被标记为 $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
控制器上放置了一个断点,我可以看到该指令未在 nodeLinkFn
中元素的 controllerDirectives
中列出(在 angular 的代码库中)。那里只有 ngModel
和 workflowInput
。
有人知道为什么会这样吗?谢谢
我忘记将模块注入应用程序。谢谢@Lex