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 *) why I keep getting Error: [$injector:unpr] Unknown provider: modalInstanceProvider <- modalInstance <- modalCtrl
error. BTW $modal
is now depricated, it's $ubiModal
now.
一切似乎都是有序的,我不能为我的生活工作(或从*找出)为什么我一直得到错误:[$ injector:unpr]未知的提供者:modalInstanceProvider < - modalInstance < - modalCtrl错误。 BTW $ 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>
1 个解决方案
#1
10
$modalInstance
has since been changed (deprecated) to $uibModalInstance
with the latest ui bootstrap (0.14.3). Also it should be $modalInstance
with older versions.
$ modalInstance已被更改(弃用)到$ uibModalInstance,带有最新的ui bootstrap(0.14.3)。它也应该是旧版本的$ modalInstance。
i.e
module.controller("modalCtrl", ["$scope", "ngDialog", "dataService", "$uibModalInstance",
function ($scope, ngDialog, dataService, $uibModalInstance) {
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
controller - 模态实例的控制器 - 它可以初始化模态使用的范围。接受“SomeCtrl as myctrl”形式的“controller-as”语法;可以使用$ uibModalInstance注入
#1
10
$modalInstance
has since been changed (deprecated) to $uibModalInstance
with the latest ui bootstrap (0.14.3). Also it should be $modalInstance
with older versions.
$ modalInstance已被更改(弃用)到$ uibModalInstance,带有最新的ui bootstrap(0.14.3)。它也应该是旧版本的$ modalInstance。
i.e
module.controller("modalCtrl", ["$scope", "ngDialog", "dataService", "$uibModalInstance",
function ($scope, ngDialog, dataService, $uibModalInstance) {
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
controller - 模态实例的控制器 - 它可以初始化模态使用的范围。接受“SomeCtrl as myctrl”形式的“controller-as”语法;可以使用$ uibModalInstance注入