角UI引导模态:[$喷油器:unpr]未知提供商:$ uibModalInstanceProvider [英] Angular UI Bootstrap Modal: [$injector:unpr] Unknown provider: $uibModalInstanceProvider
问题描述
这是一个有点奇怪。当我在网上搜索这个问题,我看到谷歌结果,所以,解决方案的许多网页...但似乎没有工作!
This is a bit strange. When I search this issue online I see many pages of Google results and SO solutions... but none seem to work!
在概括地说,我想实现AngularUI引导模态。我不断收到以下错误:
In a nutshell, I am trying to implement AngularUI Bootstrap Modal. I keep getting the following error:
错误:[$喷油器:unpr]未知提供商:$ uibModalInstanceProvider< - $ uibModalInstance< - addEntryCtrl
Error: [$injector:unpr] Unknown provider: $uibModalInstanceProvider <- $uibModalInstance <- addEntryCtrl
下面是我的HTML:
<nav class="navbar navbar-default">
<div class="container">
<span class="nav-col" ng-controller="navCtrl" style="text-align:right">
<a class="btn pill" ng-click="open()" aria-hidden="true">Add New</a>
</span>
</div>
</nav>
下面是我的控制器:
var app = angular.module('nav', ['ui.bootstrap']);
app.controller('navCtrl', ['$scope', '$uibModal', function($scope, $uibModal) {
$scope.open = function() {
var uibModalInstance = $uibModal.open({
animation: true,
templateUrl: 'addEntry/addEntry.html',
controller: 'addEntryCtrl',
});
};
}]);
最后,这里是我的语气code:
And finally, here is my modal code:
var app = angular.module('addEntry', ['firebase', 'ui.bootstrap']);
app.controller('addEntryCtrl', ['$scope', '$firebaseObject', '$state', '$uibModalInstance', function($scope, $firebaseObject, $state, $uibModalInstance) {
$scope.cancel = function() {
$uibModalInstance.dismiss('cancel');
};
$uibModalInstance.close();
}]);
解决方案我已经试过:
Solutions I've tried:
- 更新这两个角度引导(版本:0.14.3)和角度(V1.4.8)
- 改变uibModalInstance到modalInstance
- 改变$ uibModalInstance到modalInstance
- 把我addEntryCtrl我ModalInstance 里面
有什么想法?这已经推动我逼疯了近2天了。
Any thoughts? This has been driving me up the wall for almost 2 days now.
*编辑*
我要注意两件事情:
1),当我删除$ uibModalInstance从addEntry的依赖,我的HTML表单提交按钮只是正常工作和形式看起来完美。即使是正确重定向发生时(在提交)。问题仍然是:模态仍然停留在屏幕上,并抛出一个错误的$ uibModalInstance是不确定的。这是有道理的,因为我删除它作为一个依赖关系,而我显然还是需要的模式接近在提交。
1) when I remove $uibModalInstance as a dependency from addEntry, my HTML form submit buttons work just fine and the form looks perfect. Even the redirect occurs correctly (upon submission). The problem remains: the modal still stays on the screen and an error is thrown that $uibModalInstance is undefined. This makes sense since I removed it as a dependency but I obviously still need the modal is close upon submission.
2)另外,我有几乎相同的code在我的应用程序的另一部分工作。唯一的区别有,它的通过工厂工作。否则,code是相同的。因此,我相信我的依赖都在那里和版本是正确的。所以。吓坏。奇怪的。
2) Also, I have almost identical code working in another part of my app. The only difference there is that it's working via a factory. Otherwise, the code is identical. Thus, I am confident my dependencies are all there and versions are correct. So. Freaking. Strange.
谢谢!
推荐答案
答找到!我的朋友劈砍而去后,我们发现答案。我想它张贴在这里,以防万一别人读这一点。
Answer Found! After hacking away with my friend, we discovered the answer. I wanted to post it here just in case someone else reads this.
原来,我们已经在我们的模态窗口中的NG-控制器是一个div标签被打包的,这是在模态整个HTML表单。 previously,这工作得很好,当我们的形式,一个模式(它有一个单独的URL)不是,但由于某种原因它时,它是一个模式打破。在NG-控制器,引用 addEntryCtrl
。取出后,立即将形式工作!
It turns out that we had an ng-controller in our modal window that was in a div tag that wrapped the entire html form that was in the modal. Previously, this worked fine when our form was NOT in a modal (it had a separate URL) but for some reason it breaks when it is in a modal. The ng-controller was referencing the addEntryCtrl
. Immediately after removing it, the form worked!
这篇关于角UI引导模态:[$喷油器:unpr]未知提供商:$ uibModalInstanceProvider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!