未知提供者:$ templateRequestProvider< - $ templateRequest< - $ route< - ngViewDirective

时间:2014-11-19 01:29:42

标签: angularjs angularjs-directive angularjs-scope

我刚刚开始使用angular.js,我看了一些更老的东西。其中ng-route不是依赖项,因此我更改了代码并在html中添加了<script src="js/vendor/angular-route.js"></script>,但我收到了同样的错误Unknown provider: $templateRequestProvider <- $templateRequest <- $route <- ngViewDirective

HTML:

<!doctype html>
<html class="no-js" lang="en">
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>test</title>
  <link rel="stylesheet" href="css/foundation.css" />
  <link rel="stylesheet" href="css/main.css" />
  <script src="js/vendor/modernizr.js"></script>
  <script src="js/vendor/angular.js"></script>
  <script src="js/vendor/angular-route.js"></script>
  <script src="js/vendor/main.js"></script>
</head>
<body>
  <div ng-app="app">
    <ng-view></ng-view>
  </div>

</body>
</html>

JS:

var app = angular.module("app", ['ngRoute']);

app.config(['$routeProvider', function($routeProvider){
  $routeProvider.when("/",{
    templateUrl: "templates/home.html",
    controller: "AppCtrl"
  }
  );
}]);

app.controller("AppCtrl", function($scope){
  $scope.model = {
    message: "This is my app!!!"
  }
});

home.html的:

<h1>{{model.message}}</h1>

1 个答案:

答案 0 :(得分:1)

我在使用angular-route 1.3.14和angular 1.2.14时遇到了这个问题,你需要将角度升级到angular-route所需的版本。这里是角度航线1.3.14的凉亭,它需要1.3.14角。

{
    "name": "angular-route",
    "version": "1.3.14",
    "main": "./angular-route.js",
    "ignore": [],
    "dependencies": {
        "angular": "1.3.14"
    },
    "homepage": "https://github.com/angular/bower-angular-route",
    "_release": "1.3.14",
    "_resolution": {
        "type": "version",
        "tag": "v1.3.14",
        "commit": "a405245afdb0f1eac5aad4d8ddc555ed557b3345"
    },
    "_source": "git://github.com/angular/bower-angular-route.git",
    "_target": "1.3.14",
    "_originalSource": "angular-route"
}