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

查看:36
本文介绍了如何将“$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) {

但我不断收到此错误:

未知提供者:modalpartProvider <- modalpart

Unknown provider: modalpartProvider <- modalpart

我该如何解决这个问题?

How can I solve this problem?

附言我正在查看的原始代码在这里: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天全站免登陆