未知提供者:accordionDirectiveProvider

时间:2016-07-25 18:23:45

标签: javascript angularjs angular-ui-bootstrap accordion jquery-ui-sortable

有人可以帮我弄清楚我的错误在哪里吗?我使用this example在我的页面上构建可排序的手风琴。示例运行良好,但我已将此代码放入我的应用程序并出现此错误

  
    

angular.js:68未捕获错误:[$ injector:modulerr]由于以下原因无法实例化模块应用程序:错误:[$ injector:unpr]未知     提供者:accordionDirectiveProvider     http://errors.angularjs.org/1.5.7/ $注射器/ unpr?P0 = accordionDirectiveProvider         在http://localhost:63342/myapp%202.0/libs/angular/angular.js:68:20         在http://localhost:63342/myapp%202.0/libs/angular/angular.js:4502:27         at Object.getService [as get](http://localhost:63342/myapp%202.0/libs/angular/angular.js:4655:53)         at Object.decorator(http://localhost:63342/myapp%202.0/libs/angular/angular.js:4577:49)         在http://localhost:63342/myapp%202.0/js/app/app.js:56:18         at Object.invoke(http://localhost:63342/myapp%202.0/libs/angular/angular.js:4709:31)         at runInvokeQueue(http://localhost:63342/myapp%202.0/libs/angular/angular.js:4602:49)         在http://localhost:63342/myapp%202.0/libs/angular/angular.js:4611:25         at forEach(http://localhost:63342/myapp%202.0/libs/angular/angular.js:321:34)         在loadModules(http://localhost:63342/myapp%202.0/libs/angular/angular.js:4592:13)     http://errors.angularjs.org/1.5.7/ $注射器/ modulerr P0 =应用&安培; P1 =错误%3A%20%...本地主机%3A63342%2Fmyapp%25202.0%2Flibs%2Fangular%2Fangular.js%3A4592%3A13)

  

正如我从这一行可以看出我的提供者出了什么问题

http://localhost:63342/myapp%202.0/js/app/app.js:56:18 at Object.invoke 

 .config(['$provide', function ($provide){
    $provide.decorator('accordionDirective', function($delegate) {
        var directive = $delegate[0];
        directive.replace = true;
        return $delegate;
    });
}])

但是我清除了这个提供商的代码,手风琴停止工作。我的错误在哪里?我道歉但是不能在plunker中发现这个错误,所以把我的代码放在下面

    (function () {

    window.app = angular.module('app', ['ngRoute','ngAnimate', 'ui.bootstrap', 'ui.sortable', 'ngSanitize',
        'ngTouch',
        'ui.grid',
        'ui.grid.exporter',
        'ui.grid.selection',
        'ui.grid.pagination',

        'ui.grid.saveState',
        'ui.grid.cellNav',
        'ui.grid.resizeColumns',
        'ui.grid.moveColumns',
        'ui.grid.pinning',
        'ui.grid.grouping',
        'ui.grid.autoResize',

        'ui.grid.edit',
        'ui.grid.rowEdit'
    ])

        .run(['$rootScope', function($rootScope) {
            $rootScope.$on('$routeChangeSuccess', function (event, current, previous) {
                $rootScope.title = current.$$route.title;
            });
        }])

        .config(['$httpProvider', function ($httpProvider) {
            $httpProvider.defaults.useXDomain = true;
            delete $httpProvider.defaults.headers.common["X-Requested-With"];
        }])

        .config(['$routeProvider',
            function($routeProvider) {
            $routeProvider
                .when('/', {
                    title: " ",
                    controller: 'homeCtrl'
                })
                .when('/page', {
                    title: 'GRID',
                    templateUrl: 'html/pages/grid.html',
                    controller: 'gridCtrl'
                })
                .when('/designer', {
                    title: 'Design Grid',
                    templateUrl: 'html/pages/designer.html',
                    controller: 'designerCtrl'
                })
                .otherwise({
                    redirectTo: '/'
            });
        }])

    .config(['$provide', function ($provide){
        $provide.decorator('accordionDirective', function($delegate) {
            var directive = $delegate[0];
            directive.replace = true;
            return $delegate;
        });
    }])

        .filter('makeUppercase', function () {
            return function (item) {
                var space = item.replace(/\./g, " ");
                var result = space.replace(/([A-Z])/g, " $1");
                return result.charAt(0).toUpperCase() + result.slice(1)
            };
        })

}());

HTML

 <uib-accordion  ui-sortable="sortableOptions" ng-model="panels">
                <uib-accordion-group ng-repeat="panel in panels">
                <uib-accordion-heading>
                    <div class="handle"><i class="fa fa-arrows pull-left"></i></div>
                    <span class="panel-title-left">{{panel.heading}}</span>
                    <i class="caret pull-right"></i>
                </uib-accordion-heading>
                   <div ng-include=" panel.url "></div>
            </uib-accordion-group>
            </uib-accordion>

1 个答案:

答案 0 :(得分:1)

如果您使用uib-tools 1. +,则会出现此错误。在最新版本中,他们已将指令的名称从'accordion'更改为'uibAccordion',因此您可能必须使用'uibAccordionDirective'。见例子

  .config(['$provide', function ($provide){
         $provide.decorator('uibAccordionDirective', function($delegate) {
                var directive = $delegate[0];
                directive.replace = true;
                return $delegate;
            });
        }])