javascript 错误:[$injector:unpr] Unknown provider: modalInstanceProvider <- modalInstance <- modalCtrl with the latest ui bo

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33438018/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 16:28:34  来源:igfitidea点击:

Error: [$injector:unpr] Unknown provider: modalInstanceProvider <- modalInstance <- modalCtrl with the latest ui bootstrap

javascripthtmlangularjsmodal-dialogangular-ui-bootstrap

提问by notAChance

EDIT - as the code below is, the modal will work - my issue was I had included ng-app and ng-controller in my HTML template for my modal, however they are not included in the below question.

编辑 - 正如下面的代码一样,模态可以工作 - 我的问题是我在我的模态的 HTML 模板中包含了 ng-app 和 ng-controller,但是它们没有包含在下面的问题中。

I've my main controller, modal controller and my modal template HTML

我有我的主控制器、模态控制器和我的模态模板 HTML

Everything seems to be in order and I cannot for the life of me work out (or find out from stackoverflow) why I keep getting Error: [$injector:unpr] Unknown provider: modalInstanceProvider <- modalInstance <- modalCtrlerror. BTW $modalis now depricated, it's $ubiModalnow.

一切似乎都井井有条,我一生都无法弄清楚(或从 stackoverflow 中找出)为什么我总是Error: [$injector:unpr] Unknown provider: modalInstanceProvider <- modalInstance <- modalCtrl出错。顺便说一句$modal,现在被贬低了,就是$ubiModal现在。

Main ctrl:

主控制:

var module = angular.module("app", ["agGrid", "ngAnimate", "ngSanitize", "ngDialog", "ui.bootstrap"])

module.controller("mainCtrl", ["$scope", "dataService", "$timeout", "dateFilter", "ngDialog", "$http", "$uibModal", function ($scope, dataService, $timeout, dateFilter, ngDialog, $http, $uibModal) {

$scope.open = function () {

    var uibModalInstance= $uibModal.open({
        templateUrl: "views/Modal.html",
        controller: "modalCtrl",
        show: true,
    })
};
}]);

my modal controller:

我的模态控制器:

module.controller("modalCtrl", ["$scope", "ngDialog", "dataService", "$uibModalInstance", function ($scope, ngDialog, dataService, $uibModalInstance) {

//do stuff

}]);

and my HTML template:

和我的 HTML 模板:

 <div id="loginModal" class="modal show" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" ng-click="closeThisDialog(); printArray()" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h1 class="text-center" style="text-align: center">Entities:</h1>
                </div>
                <div class="modal-body">

                    <div>
                        <div>
                            <input type="text" placeholder="Search" ng-model="entity">
                        </div>
                    </div>

                    <div ng-repeat="entity in entityArray | filter:entity">

                        <label>
                            <input style="float: left; margin-top: 5px" type="checkbox" ng-model="entityChecked" ng-change="getEntityFromModal(entity, entityChecked)" />
                            <span>{{entity}}</span>
                        </label>
                    </div>
                </div>
                <button ng-click="okButtonEntity();" >OK</button>
            </div>
        </div>
    </div>

回答by PSL

$modalInstancehas since been changed (deprecated) to $uibModalInstancewith the latest ui bootstrap (0.14.3). Also it should be $modalInstancewith older versions.

$modalInstance此后已更改(弃用)为$uibModalInstance最新的 ui 引导程序 (0.14.3)。它也应该$modalInstance与旧版本。

i.e

IE

module.controller("modalCtrl", ["$scope", "ngDialog", "dataService", "$uibModalInstance", 
                        function ($scope, ngDialog, dataService, $uibModalInstance) {

Documentation

文档

controller - a controller for a modal instance - it can initialize scope used by modal. Accepts the "controller-as" syntax in the form 'SomeCtrl as myctrl'; can be injected with $uibModalInstance

控制器 - 模态实例的控制器 - 它可以初始化模态使用的范围。接受形式为“SomeCtrl as myctrl”的“controller-as”语法;可以用 $uibModalInstance 注入