AngularJS指令提供未知提供程序未知

时间:2018-03-17 16:41:08

标签: angularjs angularjs-directive

当我的模态加载到我的AngularJS应用程序中时,出现以下错误:

  

$注射器:unpr   未知的提供商   未知提供者:eProvider< - e

这是我的指示:

(function () {

    angular.module('myApp').directive('ssdropdownmulti', [ssdropdownmulti]);

        function ssdropdownmulti() {

            return {
                restrict: 'E',
                scope: {
                    model: '=',
                    options: '=',
                    pre_selected: '=preSelected',
                    dropdownTitle: '@'
                },
                template : "<div class='btn-group' ng-class='{open: open}'>" +
                           "<button class='btn btn-small'>{{dropdownTitle}}</button>" +
                           "<button class='btn btn-small dropdown-toggle' ng-click='open=!open;openDropDown()'><span class='caret'></span></button>" +
                           "<ul class='dropdown-menu scrollable-menu' aria-labelledby='dropdownMenu'>" +
                           "<li><input type='checkbox' ng-change='checkAllClicked()' ng-model=checkAll> Check All</li>" +
                           "<li class='divider'></li>" +
                           "<li ng-repeat='option in options'><input type='checkbox' ng-change='setSelectedItem(option.id)' ng-model='selectedItems[option.id]'>{{option.name}}</li>" +
                           "</ul></div>",
                controller : function ($scope) {

                    ... other code...
        } // end constructor function
})();

这是我的观点html:

<ssdropdownmulti dropdown-title="Select Employees"
                 pre-selected="vm.plannedEmployees[0].id"
                 model="selected_items"
                 options="vm.plannedEmployees">

但是在这个小提琴中,代码运行正常: http://jsfiddle.net/jab4raoq/336/

1 个答案:

答案 0 :(得分:-1)

应该是这样的:

angular.module('myApp').directive('ssdropdownmulti', function ssdropdownmulti() {
..
});

指令定义与注入不同。如果你想在函数中注入一些东西,那就像是:

angular.module('myApp').directive('ssdropdownmulti', 
       ['$timeout',function ssdropdownmulti($timeout) {
..
}]);