简体   繁体   English

未知提供程序:尝试更改其模板时,uibCarouselProvider

[英]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.

相关问题 尝试从另一个模块获取常量时,角度未知的提供程序 - Angular unknown provider when trying to get a constant from another module 尝试从另一个模块插入服务时出现未知的提供程序错误 - Unknown provider error when trying to inject a service from another module 尝试依赖向AngularJs中的控制器注入服务时出现未知的提供程序错误 - Unknown provider error when trying to dependency inject a service to a controller in AngularJs 未知提供程序:尝试使用Angular ngStorage时ngStorageProvider &lt;-ngStorage - Unknown provider: ngStorageProvider <- ngStorage when trying to use Angular ngStorage 尝试在Angular控制器上注入依赖项时出现未知提供程序错误 - Unknown provider Error when trying to inject dependency on Angular controller 注入常​​量时,未知提供程序的错误抛出 - Unknown provider's error throw when injecting constant 尝试在ionic中调用配置提供程序时,我似乎正在获取未知的提供程序错误 - I seem to be gettting an unknown provider error when I am trying to call the config provider in ionic 测试工厂时未知的提供者 - Unknown provider when testing factory 尝试包含ngMaterial $ mdToast时,Angular Material“[$ injector:unpr]未知提供程序”错误,$ animate - Angular Material “[$injector:unpr] Unknown provider” errors when trying to include ngMaterial $mdToast, $animate 尝试使用$ cookies时出现未知提供程序错误 - Get Unknown Provider Error trying to use $cookies
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM