[英]AngularJS and ui-bootstrap injection error(?)
Forgive me if this error is somewhat simple, but i seem to be getting these injection error and the debugger in firefox doesn't seem to help me. 如果这个错误有点简单,请原谅我,但是我似乎遇到了这些注入错误,firefox中的调试器似乎对我没有帮助。 Here the code snippets
这里的代码片段
This is the Controller file in question 这是有问题的控制器文件
App.controller('ModalInstanceCtrl', function ($scope,$uibModal, menuAppetizers) {
$scope.menuAppetizers; });
App.controller('AppetizerMenuController',
['$rootScope', '$scope', '$http', 'ParseService', '$location', '$q', '$uibModal',
function ($rootScope, $scope, $http, $location, ParseService, $q, $uibModal) {
//.... needless code not related to the problem
$scope.open = function (_menuAppetizer) {
console.log("We get into the modal open");
var modalInstance = $uibModal.open({
controller: 'ModalInstanceCtrl',
templateUrl: "Views/menu/myModal.html",
resolve: function () {
return _menuAppetizer;
}
});
}
}]);
in the app.js file where i call for ui-bootstrap: 在我要求ui-bootstrap的app.js文件中:
var App = angular.module('App',
['ngRoute', "ui.bootstrap"])
Which seem to look fine to me. 在我看来,这看起来不错。 This consist most of the routing for my project.
这包括我项目的大部分路由。
The view for the AppetizersController which only show the modal snippet: AppetizersController的视图仅显示模式片段:
<button type="button" class="btn btn-default btn-sm" ng-click="open(menuAppetizers)"
data-toggle="modal" data-target="#myModal.html">Nutrition Info</button>
Which should go to the modal.html and open that content which is listed here 哪个应该转到modal.html并打开此处列出的内容
<div class="modal fade" id="myModal.html" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Nutrition Info</h4>
</div>
<div class="modal-body">
<p>Calories: {{menuAppetizers.NutritionInfo}}</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
Sorry if i didn't post enough code, I can get the modal to work, but when i try to use $modal.open it return a injector error. 抱歉,如果我没有发布足够的代码,我可以使模态正常工作,但是当我尝试使用$ modal.open时,它会返回注射器错误。 Did i make a mistake injecting?
我注射有误吗? I looked up this problem and i seem to be following the rules i got from the documentation from ui-bootstrap.
我查了一下这个问题,似乎遵循了ui-bootstrap文档中的规则。 Am I missing something?
我想念什么吗? I'm pretty new to angularjs/ui-bootstrap.
我对angularjs / ui-bootstrap很陌生。
Error I get: 错误我得到:
Error: [$injector:unpr] http://errors.angularjs.org/1.4.7/$injector/unpr?p0=menuAppetizersProvider%20%3C-%20menuAppetizers%20%3C-%20ModalInstanceCtrl
e/<() angular.min.js:107
Ze/this.$get</<() angular.min.js:80
f/<() angular.min.js:119
lf/this.$get</n.prototype.$eval() angular.min.js:133
lf/this.$get</n.prototype.$digest() angular.min.js:130
lf/this.$get</n.prototype.$apply() angular.min.js:133
h() angular.min.js:87
K() angular.min.js:91
Sf/</z.onload()
There is a mistake in the injection: 注入中有一个错误:
App.controller('ModalInstanceCtrl', ['$scope', '$uibModal', 'menuAppetizers',function ($scope,$uibModal, menuAppetizers) {
$scope.menuAppetizers; }]);
App.controller('AppetizerMenuController',
['$rootScope', '$scope', '$http', '$location', 'ParseService', '$q', '$uibModal',
function ($rootScope, $scope, $http, $location, ParseService, $q, $uibModal) {
.... needless code not related to the problem
'ParseService', '$location', '
where inverted. 'ParseService', '$location', '
颠倒了。
Your resolve should be: 您的决心应该是:
resolve: {
menuAppetizers: function () {
return _menuAppetizer;
}
}
In your controller, you declared a menuAppetizers dependency, but in your resolve, you did not declare a menuAppetizers object instead you declared a function, that's why it is not working. 在您的控制器中,您声明了menuAppetizers依赖项,但在您的解决方案中,您没有声明menuAppetizers对象,而是声明了一个函数,这就是它不起作用的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.