[英]Unknown provider: uibCarouselProvider when trying to change it's template
I am trying to get angularjs to play nicely with local templates that override bootstrap ones. 我正在尝试让angularjs与覆盖自举模板的本地模板很好地协作。 I had initially use the same file path (uib/template/carousel/carousel.html for example) which is fine when published, but locally it doesn't work.
我最初使用的是相同的文件路径(例如,uib / template / carousel / carousel.html),在发布时可以使用,但是在本地不起作用。
So, I found this soluton: Angular ui bootstrap directive template missing 因此,我发现此解决方案: 缺少Angular ui bootstrap指令模板
They have said you can override the template with a new url with the $provide service. 他们说您可以使用$ provide服务使用新的URL覆盖模板。 So I have done this:
所以我做到了:
'use strict';
angular.module('core').config(coreConfig);
function coreConfig($provide) {
$provide.decorator('uibCarousel', function ($delegate) {
console.log($delegate[0]);
$delegate[0].templateUrl = 'bootstrap/carousel/carousel.html';
return $delegate;
});
};
which should work. 这应该工作。 my core module looks like this:
我的核心模块如下所示:
'use strict';
angular.module('core', [
'ngCookies',
'ngNotify',
'ngResource',
'ngSimpleCache',
'ui.bootstrap',
'ui.bootstrap.tpls',
'ui.router',
'ui.select',
// -- remove for brevity -- //
]);
As you can see, I have the ui.bootstrap.tpls
module loaded, so in theory, my code should work. 如您所见,我已经加载了
ui.bootstrap.tpls
模块,因此从理论上讲,我的代码应该可以工作。 Can anyone think of a reason that it won't? 谁能想到不会的原因?
Sorry for all the comment spam. 对不起,所有评论垃圾邮件。 I think I have found the answer to your issue.
我想我已经找到您问题的答案。 You must append
Directive
to a directive when defining the decorator: 定义装饰器时,必须将
Directive
附加到指令:
function coreConfig($provide) {
$provide.decorator('uibCarouselDirective', function ($delegate) {
console.log($delegate[0]);
$delegate[0].templateUrl = 'bootstrap/carousel/carousel.html';
return $delegate;
});
};
From the docs: 从文档:
Decorators have different rules for different services.
装饰器针对不同的服务具有不同的规则。 This is because services are registered in different ways.
这是因为服务是以不同的方式注册的。 Services are selected by name, however filters and directives are selected by appending "Filter" or "Directive" to the end of the name.
通过名称选择服务,但是通过在名称末尾附加“ Filter”或“ Directive”来选择过滤器和指令。 The $delegate provided is dictated by the type of service.
提供的$ delegate由服务类型决定。
https://docs.angularjs.org/guide/decorators https://docs.angularjs.org/guide/decorators
This is an example from my own (working) code: 这是我自己(工作)代码中的一个示例:
$provide.decorator("uibDatepickerPopupDirective", [
"$delegate",
function($delegate) {
var directive = $delegate[0];
// removed for brevity
return $delegate;
}
]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.