如何注入控制器内部$ modalInstance? [英] How to inject $modalInstance inside a controller?

查看:132
本文介绍了如何注入控制器内部$ modalInstance?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序后,我发现了一个用户未登录我想开一个模态对话框:

In my application after i found out that a user is not logged in i want to open a modal dialog:

  .when('/showtask/:id', {templateUrl: 'Home/Template/showtask', resolve: ShowTaskCtrl.resolve, access: { allowAnonymous: false },
            resolve: {
        userAuthenticated: ["$http", "$q", function ($http, $q) {
            var deferred = $q.defer();
            $http.get('/api/Authentication/UserAuthenticated').then(function (data) {

                if (data.data != "null") {
                    deferred.resolve(data.data);
                }
                else {

                    var modalInstance = {
                        templateUrl: 'Home/Template/loginfailed',
                        controller: 'ModalInstanceCtrl',
                        modalpart: ['modalpart', function (modalpart) {
                            return modalInstance;
                            }]
                    };
                    $modal.open(modalInstance);

                    deferred.reject();

                }   
            });
            return deferred.promise;

        }]

    }

由于它在途中发生了变化,我有注入一个实例内modalpart和控制器retrive它。

Since it is happening on route change i have to inject a modalpart inside an instance and retrive it in controller.

var ModalInstanceCtrl = WorkerApp.controller('ModalInstanceCtrl', ["$scope", "modalpart", function ($scope, modalpart) {

但我不断收到此错误:

but i keep getting this error:

未知提供商:modalpartProvider< - modalpart

Unknown provider: modalpartProvider <- modalpart

我怎样才能解决这个问题?

How can i solve this problem?

P.S。起源$ C ​​$ C,我看是在这里: http://angular-ui.github.io/bootstrap/(下模态)

P.S. origin code which i looking at is here: http://angular-ui.github.io/bootstrap/ (under modal)

推荐答案

有这个问题一段时间为好。虽然你没有张贴你的HTML,那就是我的问题了。确保你没有在DOM命名控制器,这已经得到照顾您在$ modal.open()。

Had this problem for awhile as well. Although you didn't post your HTML, that is where my problem was. Make sure you do not name the controller in your DOM, this has already been taken care of for you in $modal.open().

这篇关于如何注入控制器内部$ modalInstance?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆