AngularJS错误:[$ injector:unpr]未知提供程序 [英] AngularJS Error: [$injector:unpr] Unknown provider

查看:72
本文介绍了AngularJS错误:[$ injector:unpr]未知提供程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

定义URL路由后,出现以下错误-遵循AngularJS书中的sportsStore应用进行学习.

I am getting these errors shown below after defining the URL routes - following the sportsStore app from an AngularJS book for learning purposes.

  1. 错误:[$ injector:unpr]未知提供程序:$ templateRequestProvider<-$ templateRequest<-$ route<-ngViewDirective
  2. 错误:[$ injector:cdep]发现循环依赖项:ngViewDirective

我已经阅读了与此类错误有关的所有文章,并检查了angular.js和angular-route.js的版本是否相同(最后一个稳定版本). 我还阅读了有关AngularJS API的文档,并确保此处描述的原因不是这种情况.

I've read all the posts related to this type of error and I checked the versions of the angular.js and angular-route.js to be the same (the last stable version). I've read also the documentation on the AngularJS API and make sure that the causes described there are not the case.

我不知道下一步该怎么做,因为我无法理解图像中显示的浏览器开发人员工具中的错误.请为我指出正确的方向.

I don't know what to do next since it is impossible for me to understand the error from the browser's developer tools shown in the image. Please point me to the right direction.

这是app.html,其中定义了路由以显示特定视图:

Here is the app.html where the routes are defined to display the specific views:

<!DOCTYPE html>
<html ng-app="sportsStore">

<head>
  <title>SportsStore</title>
  <script src="angular.js"></script>
  <link href="bootstrap.css" rel="stylesheet" />
  <link href="bootstrap-theme.css" rel="stylesheet" />
  <script>
    angular.module("sportsStore", ["customFilters", "cart", "ngRoute"])
      .config(function($routeProvider) {

        $routeProvider.when("/checkout", {
          templateUrl: "/views/checkoutSummary.html"
        });

        $routeProvider.when("/products", {
          templateUrl: "/views/productList.html"
        });

        $routeProvider.otherwise({
          templateUrl: "/views/productList.html"
        });
      });
  </script>
  <script src="controllers/sportsStore.js"></script>
  <script src="filters/customFilters.js"></script>
  <script src="controllers/productListControllers.js"></script>
  <script src="components/cart/cart.js"></script>
  <script src="ngmodules/angular-route.js"></script>
</head>

<body ng-controller="sportsStoreCtrl">
  <div class="navbar navbar-inverse">
    <a class="navbar-brand" href="#">SPORTS STORE</a>
    <cart-summary />
  </div>

  <div class="alert alert-danger" ng-show="data.error">
    Error ({{data.error.status}}). The product data was not loaded.
    <a href="/app.html" class="alert-link">Click here to try again</a>
  </div>
  <ng-view />
</body>

</html>

在不更改代码的情况下,我还有另一个错误.这太奇怪了:

Without changing the code I have another error. This is so strange:

推荐答案

@uamanager向我展示了解决方案->在templateUrl中的视图之前删除'/'

@uamanager showed me the solution -> to remove the '/' right before the views in the templateUrl

<script>
    angular.module("sportsStore", ["customFilters", "cart", "ngRoute"])
    .config(function ($routeProvider) {

        $routeProvider.when("/checkout", {
            templateUrl: "views/checkoutSummary.html"
        });

        $routeProvider.when("/products", {
            templateUrl: "views/productList.html"
        });

        $routeProvider.otherwise({
            templateUrl: "views/productList.html"
        });
    });
</script>

这篇关于AngularJS错误:[$ injector:unpr]未知提供程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆