简体   繁体   English

错误:$ injector:unpr未知提供程序:itemslistProvider <-

[英]Error: $injector:unpr Unknown Provider: itemslistProvider <-

I have been debugging the code for around several days but unable to find the solution. 我已经调试了大约几天的代码,但找不到解决方案。 I have read the angularjs documentation as well as several existing SO questions for the error but still unable to spot any of the error due to which the code is failing. 我已经阅读了angularjs文档以及该错误的几个现有SO问题,但仍无法发现由于代码失败而导致的任何错误。

This is one of my assignment which I have almost completed and written the code for it but I am just stuck in displaying the items in a category. 这是我的一项工作,我几乎完成了工作并为其编写了代码,但是我只是停留在显示类别中的项目上。 The code for displaying the category is working fine but the very similar code for displaying the item is not. 用于显示类别的代码可以正常工作,但用于显示项目的代码却非常相似。 I am really confused and hit a dead end. 我真的很困惑,死胡同。 I request you to only give me a hint or a line where I may be going wrong. 我要求您只给我一个提示或可能会出错的行。 I am not requesting the whole solution because it is against the honor code. 我并没有要求整个解决方案,因为它违反了荣誉守则。

So, here are the files 所以,这是文件

index.html index.html

<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8">
 <link rel="stylesheet" href="css/styles.css">
 <title>My Restro</title>
</head>
<body ng-app="MenuApp">
<ui-view></ui-view>

<!-- Libraries -->
<script src="lib/angular.min.js"></script>
<script src="lib/angular-ui-router.min.js"></script>

 <!-- Modules -->
 <script src="src/menuapp/menuapp.module.js"></script>
 <script src="src/menuapp/data.module.js"></script>
 <!-- Routes -->
 <script src="src/routes.js"></script>

 <!-- 'MenuApp' module artifacts -->
 <script src="src/menuapp/menudata.service.js"></script>
 <script src="src/menuapp/categories.component.js"></script>
 <script src="src/menuapp/categories.controller.js"></script>
 <script src="src/menuapp/items.component.js"></script>
 <script src="src/menuapp/item-detail.controller.js"></script>
 <!-- <script src="src/menuapp/main-menuapp.controller.js"></script> -->
</body>
</html>

item-detail.controller: item-detail.controller:

(function () {
  'use strict';

  angular.module('MenuApp')
  .controller('ItemDetailController', ItemDetailController);

  // 'itemlist' is injected through state's resolve
  ItemDetailController.$inject = ['MenuDataService','itemslist'];
  function ItemDetailController(MenuDataService,itemslist) {
    var itemDetailCtrl = this;
    itemDetailCtrl.itemslist=itemslist;
   }

   })();

routes.js routes.js

(function () {
 'use strict';

  angular.module('MenuApp')
  .config(RoutesConfig);

   RoutesConfig.$inject = ['$stateProvider', '$urlRouterProvider'];
   function RoutesConfig($stateProvider, $urlRouterProvider) {

  .........//other states code.....
  //items state code
  .state('items', {
    url: '/items/{categoryShortName}',
    templateUrl: 'src/menuapp/templates/item-detail.template.html',
    controller: 'ItemDetailController as itemDetailCtrl',
    resolve: {
        itemlist: ['$stateParams', 'MenuDataService',
        function ($stateParams, MenuDataService) {
          return MenuDataService.getItemsForCategories($stateParams.categoryShortName);
        }]
    }
  });
 }

 })();

In your route you have resolve name itemlist and you injecting it as itemslist. 在您的路线中,您具有解析名称itemlist,并将其注入为itemslist。 Ii should be like this. 我应该是这样的。

ItemDetailController.$inject = ['MenuDataService','itemlist'];
function ItemDetailController(MenuDataService,itemlist) {
  var itemDetailCtrl = this;
  itemDetailCtrl.itemlist=itemlist;
}

})(); })();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM