本文介绍了错误:$喷油器:unpr未知提供商时添加$ uibModalInstance到控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我$ uibModalInstance添加到我的控制器,我得到的错误:

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

我的控制器被定义为:

  angular.module('myWebApp.controllers')。
    控制器('EventAdditionalInformationTabCtrl',函数($范围,$ uibModalInstance,EVENTDATA){
});

我还有一个控制器,它定义了开放的功能:

 控制器('modalCtrl',函数($范围,$ uibModal){
    $ scope.open =功能(模板,例如,大小){
        VAR modalInstance = $ uibModal.open({
            动画:真实,
            templateUrl:模板,
            控制器:例如,
            大小:大小
        });
    };
})。

然后我想通过将处理模式的特定实例的控制,在这种情况下 EventAdditionalInformationTabCtrl

我的应用程序被定义为:

  VAR应用= angular.module('myWebApp',[
    myWebApp.services',
    myWebApp.controllers',
    ui.router',
    duScroll',
    ngAnimate',
    ui.bootstrap',
    angularUtils.directives.dirPagination',
    角装吧
]);

我是什么失踪?

编辑----

下面是EventAdditionalInformationTabCtrl是如何链接到的UI路由器的看法。

  $ stateProvider
        .STATE('事件',{
            网址:'/事件',
            params:一个{
                事件ID:空
            },
            解析:{
                EVENTDATA:['$ HTTP,$ stateParams',函数($ HTTP,$ stateParams){
                    的console.log('事件ID:'+ $ stateParams.eventId);
                    返回$ http.get(的http://本地主机:1056​​9 / API /使用EventView /'+ $ stateParams.eventId)。然后(功能(响应){
                        返回response.data;
                    });
                }]
            },
            观点:{
                '':{
                    templateUrl:'谐音/事件/ event.html
                    //控制器:'EventCtrl
                },
                eventHeader @事件:{
                    templateUrl:'谐音/活动/事件了header.html',
                    控制器:'EventHeaderCtrl
                },
                eventOverviewTab @事件:{
                    templateUrl:'谐音/活动/事件概述-tab.html',
                    控制器:'EventOverviewTabCtrl
                },
                eventDSOTab @事件:{
                    templateUrl:'谐音/活动/事件DSO-tab.html',
                    控制器:'EventDSOTabCtrl
                },
                eventAdditionalInformationTab @事件:{
                    templateUrl:'谐音/活动/事件的附加信息,tab.html',
                    控制器:'EventAdditionalInformationTabCtrl
                },
                eventFooter @事件:{
                    templateUrl:'谐音/活动/事件footer.html',
                    控制器:'EventFooterCtrl
                }
            }
        });


解决方案

您需要注入'$ uibModal'到控制器中。

https://angular-ui.github.io退房的角度UI文档/引导/#/莫代尔

编辑:

更改此

 动画:真实,
    templateUrl:模板,
    控制器:例如,
    大小:大小

这个

 动画:真实,
    templateUrl:模板,
    控制器:EventAdditionalInformationTabCtrl,
    大小:大小

When I add $uibModalInstance to my controller I get the error:

Unknown provider: $uibModalInstanceProvider <- $uibModalInstance <- EventAdditionalInformationTabCtrl

My controller is defined as:

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

I have another controller that defines the open function:

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

Then I want to pass the controller that will handle a specific instance of a modal, in this case EventAdditionalInformationTabCtrl.

My app is defined as:

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

What am I missing?

EDIT ----

Here's how EventAdditionalInformationTabCtrl is linked to the view in 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'
                }
            }
        });
解决方案

You need to inject '$uibModal' into your controller.

Check out the angular ui docs here https://angular-ui.github.io/bootstrap/#/modal

EDIT:

Change this

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

to this

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

这篇关于错误:$喷油器:unpr未知提供商时添加$ uibModalInstance到控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 03:10