[英]Extend angular bootstrap confirm directive
I have to add some application specific functionality to angular bootstrap confirm directive . 我必须向角度引导确认指令添加一些特定于应用程序的功能。
I can easily use it directly in my code but when I try to use it by creating my own directive, I keep on getting module injector error. 我可以轻松地在代码中直接使用它,但是当我尝试通过创建自己的指令来使用它时,我会不断遇到模块注入器错误。
Error: [$injector:unpr] http://errors.angularjs.org/1.5.8/$injector/unpr?p0=mwlConfirmProvider%20%3C-%20mwlConfirm%20%3C-%20myDirective
Global Declaration 全球宣言
angular.module('myModule',
[
'ui.bootstrap',
'ngSanitize',
'mwl.confirm'
]);
Directive 指示
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);
}
}
What's wrong with the code? 代码有什么问题?
I don't think you can inject directives as a dependency into another directive. 我认为您不能将指令作为依赖项注入到另一个指令中。 You can do this with services and factories, but directives are applied to the DOM. 您可以使用服务和工厂来执行此操作,但是指令将应用于DOM。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.