如何将"$ modalInstance"注入控制器? [英] How to inject '$modalInstance' into a controller?

查看:77
本文介绍了如何将"$ 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并在控制器中检索它.

Since it is happening on route change I have to inject a modalpart inside an instance and retrieve it in the 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.我正在查看的原始代码在这里: http://angular-ui.github.io/bootstrap/(在模式下)

P.S. Original code which I am 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天全站免登陆