【问题标题】:Extend angular bootstrap confirm directive扩展角度引导确认指令
【发布时间】:2017-04-21 15:10:40
【问题描述】:

我必须向 angular bootstrap 确认 directive 添加一些特定于应用程序的功能。

我可以轻松地直接在我的代码中使用它,但是当我尝试通过创建自己的指令来使用它时,我不断收到模块注入器错误。

Error: [$injector:unpr] http://errors.angularjs.org/1.5.8/$injector/unpr?p0=mwlConfirmProvider%20%3C-%20mwlConfirm%20%3C-%20myDirective

全球宣言

angular.module('myModule',
[
    'ui.bootstrap',
    'ngSanitize',
    'mwl.confirm'
]);

指令

angular
    .module('myModule')
    .directive('myDirective', directive);

directive.$inject = ['mwlConfirm'];

function directive(mwlConfirm) {
    return {
        restrict: 'A',
        link: linkFunction
    };

    function linkFunction(scope, element, attrs) {

          //code removed for brevity
          var confirmOptions = ...
          ...
          ...
          mwlConfirm.value('confirmationPopoverDefaults', confirmOptions);
    }
}

代码有什么问题?

【问题讨论】:

标签: javascript angularjs twitter-bootstrap


【解决方案1】:

我认为您不能将指令作为依赖项注入另一个指令。您可以使用服务和工厂来执行此操作,但指令会应用于 DOM。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-17
    • 2013-05-23
    • 1970-01-01
    • 1970-01-01
    • 2022-11-18
    • 2013-06-05
    • 1970-01-01
    相关资源
    最近更新 更多