错误:将$ uibModalInstance添加到控制器时$ injector:unpr未知提供程序

时间:2016-03-28 18:24:01

标签: angularjs

当我将$ uibModalInstance添加到我的控制器时,我收到错误:

未知提供商:$uibModalInstanceProvider <- $uibModalInstance <- EventAdditionalInformationTabCtrl

我的控制器定义为:

angular.module('myWebApp.controllers').
    controller('EventAdditionalInformationTabCtrl', function ($scope, $uibModalInstance, eventData) {
});

我有另一个定义open函数的控制器:

controller('modalCtrl', function ($scope, $uibModal) {
    $scope.open = function (template, instance, size) {
        var modalInstance = $uibModal.open({
            animation: true,
            templateUrl: template,
            controller: instance,
            size: size
        });
    };
}).

然后我想传递将处理模态的特定实例的控制器,在本例中为EventAdditionalInformationTabCtrl

我的应用定义为:

var app = angular.module('myWebApp', [
    'myWebApp.services',
    'myWebApp.controllers',
    'ui.router',
    'duScroll',
    'ngAnimate',
    'ui.bootstrap',
    'angularUtils.directives.dirPagination',
    'angular-loading-bar'
]);

我错过了什么?

编辑----

以下是EventAdditionalInformationTabCtrl如何链接到ui-Router中的视图。

   $stateProvider
        .state('event', {
            url: '/event',
            params: {
                eventId: null
            },
            resolve: {
                eventData: ['$http', '$stateParams', function ($http, $stateParams) {
                    console.log('EventId: ' + $stateParams.eventId);
                    return $http.get('http://localhost:10569/api/eventView/' + $stateParams.eventId).then(function(response) {
                        return response.data;
                    });
                }]
            },
            views: {
                '': {
                    templateUrl: 'partials/events/event.html'
                    //controller: 'EventCtrl'
                },
                'eventHeader@event' : {
                    templateUrl: 'partials/events/event-header.html',
                    controller: 'EventHeaderCtrl'
                },
                'eventOverviewTab@event': {
                    templateUrl: 'partials/events/event-overview-tab.html',
                    controller: 'EventOverviewTabCtrl'
                },
                'eventDSOTab@event': {
                    templateUrl: 'partials/events/event-dso-tab.html',
                    controller: 'EventDSOTabCtrl'
                },
                'eventAdditionalInformationTab@event': {
                    templateUrl: 'partials/events/event-additional-information-tab.html',
                    controller: 'EventAdditionalInformationTabCtrl'
                },
                'eventFooter@event': {
                    templateUrl: 'partials/events/event-footer.html',
                    controller: 'EventFooterCtrl'
                }
            }
        });

2 个答案:

答案 0 :(得分:-1)

您现在$uibModalInstance的位置应为$uibModal。如果要实际创建模态,请使用$uibModalInstanceThis plunker$uibModal如何使用<ul class="gfield_checkbox" id="input_4_67"><li class="gchoice_4_67_1"> <input name="input_67.1" type="checkbox" value="1160" id="choice_4_67_1" tabindex="3"> <label for="choice_4_67_1" id="label_4_67_1">3-D Printing</label> </li><li class="gchoice_4_67_2"> <input name="input_67.2" type="checkbox" value="512" id="choice_4_67_2" tabindex="4"> <label for="choice_4_67_2" id="label_4_67_2">3-D Technology: Rapid Manufacturing/Prototyping Equipment</label> </li><li class="gchoice_4_67_3"> <input name="input_67.3" type="checkbox" value="962" id="choice_4_67_3" tabindex="5"> <label for="choice_4_67_3" id="label_4_67_3">Additives: Accelerators</label> </li><li class="gchoice_4_67_4"> <input name="input_67.4" type="checkbox" value="963" id="choice_4_67_4" tabindex="6"> <label for="choice_4_67_4" id="label_4_67_4">Additives: Antiblocking Agents</label> </li><li class="gchoice_4_67_5"> <input name="input_67.5" type="checkbox" value="964" id="choice_4_67_5" tabindex="7"> <label for="choice_4_67_5" id="label_4_67_5">Additives: Antifogging agents</label> </li> </ul> 的示例。

答案 1 :(得分:-1)

您需要将'$ uibModal'注入您的控制器。

在这里查看角度ui文档https://angular-ui.github.io/bootstrap/#/modal

编辑:

更改此

    animation: true,
    templateUrl: template,
    controller: instance,
    size: size

到这个

    animation: true,
    templateUrl: template,
    controller: EventAdditionalInformationTabCtrl,
    size: size
相关问题