Javascript 未知提供程序:$uibModalInstanceProvider - Bootstrap UI 模式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33455271/
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
Unknown provider: $uibModalInstanceProvider - Bootstrap UI modal
提问by Marcinek
I have a problem with UI Bootstrap modal.
我有 UI Bootstrap 模式的问题。
In one controller I have this:
在一个控制器中,我有这个:
app.controller("tableCtrl",['$scope','$http','$uibModal','$log' ,function ($scope, $http,$uibModal,$log) {
$scope.open = function (size,selectedUser) {
var modalInstance = $uibModal.open({
animation: $scope.animationsEnabled,
templateUrl: 'myModalContent.html',
controller:'ModalInstanceCtrl',
size: size,
resolve: {
user: function () {
return selectedUser;
}
}
});
}]);
In another I have this:
在另一个我有这个:
app.controller('ModalInstanceCtrl',['$scope','$uibModalInstance','user', function ($scope, $uibModalInstance, user) {
$scope.user = user;
$scope.ok = function () {
$uibModalInstance.close();
};
}]);
myModalContent
looks like this:
myModalContent
看起来像这样:
<script type="text/ng-template" id="myModalContent.html">
<div class="modal-header"><h1>EDIT</h1></div>
<div class="modal-body">
{{patient.patient_id}}
</div>
<div class="modal-footer">
<button class="btn btn-primary" type="button" ng-click="ok()">OK</button>
</div>
</script>
I only call tableCtrl
in HTML and call open
function like this:
我只调用tableCtrl
HTML 并调用open
函数,如下所示:
<button class="btn btn-primary" ng-click="open('lg',patient)">Edit</button>
When I click the edit button I receive this exception:
当我单击编辑按钮时,我收到此异常:
Unknown provider: $uibModalInstanceProvider <- $uibModalInstance
I saw this plunkerbut it didnt help me.
我看到了这个 plunker,但它没有帮助我。
What is wrong?
怎么了?
回答by GeorgeKach
I had the same problem, so from my solution here's how you could solve your scenario
我遇到了同样的问题,所以根据我的解决方案,您可以如何解决您的情况
app.controller("tableCtrl",['$scope','$http','$uibModal','$log' ,function ($scope, $http,$uibModal,$log) {
$scope.open = function (size,selectedUser) {
var uibModalInstance = $uibModal.open({
animation: $scope.animationsEnabled,
templateUrl: 'myModalContent.html',
controller:function($uibModalInstance ,$scope,user){
$scope.ok = function () {
$uibModalInstance.dismiss('cancel');
};
},
size: size,
resolve: {
user: function () {
return selectedUser;
}
}
});
}]);
回答by Aashish Patil
The Problem Identified is: My Control was reinitializing from HTML Page. Make sure the Modal controller is initalized from one place
确定的问题是:我的控件正在从 HTML 页面重新初始化。确保从一处初始化 Modal 控制器
回答by Mohamad Ghafourian
I Had the exact same problem. updating both angular and ui-bootstap library fixed my problem. Use bower to update ui-bootstrap, it suggests the version of angular that is working with it. Hope I helped.
我有同样的问题。更新 angular 和 ui-bootstap 库解决了我的问题。使用 bower 更新 ui-bootstrap,它建议使用它的 angular 版本。希望我有所帮助。
回答by nuander
I found that this problem occurred when I defined the controller in the template HTML rather than in the modal.open call
我发现这个问题发生在我在模板 HTML 中而不是在 modal.open 调用中定义控制器时
回答by KaiserKatze
Different versions of angular-ui/boostrap have different injecter variable names.
不同版本的 angular-ui/boostrap 有不同的注入器变量名称。
Check out angular-ui/bootstrap example.
回答by JimmyBob
Having the controller function, inline and inside the uibModalInstance object definition was causing me the same issue.
具有控制器函数、内联和 uibModalInstance 对象定义内部导致了我同样的问题。
After upgrading to 0.14.3, when the javascript was uglified, uibModalInstance was throwing unknown provider. Defining the controller using 'app.controller', fixed the issue.
升级到 0.14.3 后,当 javascript 被丑化时, uibModalInstance 抛出了未知的提供者。使用“app.controller”定义控制器,解决了这个问题。