第二个AngularJS指令没有从html属性加载

时间:2017-05-05 23:03:19

标签: angularjs angularjs-directive angular-directive

我有这个指令,可以避免将输入标记为$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控制器上放了一个断点,我可以看到该指令没有列在controllerDirectivesnodeLinkFn的元素中(在angular的代码库中)。那里只有ngModelworkflowInput

任何人都知道为什么会发生这种情况?谢谢

0 个答案:

没有答案