我是AngularJS的新手,在Chrome上运行AngularJS教程7时遇到了07的问题。在Chrome上,控制台上有以下错误:
angular.js:10126 Error: [$injector:unpr] Unknown provider: $templateRequestProvider <- $templateRequest <- $route <- ngViewDirective
http://errors.angularjs.org/1.2.28/$injector/unpr?p0=%24templateRequestProvider%20%3C-%20%24templateRequest%20%3C-%20%24route%20%3C-%20ngViewDirective
at VALIDITY_STATE_PROPERTY (angular.js:78)
at angular.js:3801
at Object.getService [as get] (angular.js:3929)
at angular.js:3806
at getService (angular.js:3929)
at Object.invoke (angular.js:3956)
at angular.js:3807
at getService (angular.js:3929)
at Object.invoke (angular.js:3956)
at angular.js:5716屏幕截图

同时,网页/AngularJS可以在Internet和Opera上工作,所以我想这可能是特定于Chrome的问题吧?下面是相同页面的IE视图,它工作正常。

我使用的代码与本教程可用的代码相同,但我列出了app.js和controllers.js文件,以防万一。
app.js
'use strict';
/* App Module */
var phonecatApp = angular.module('phonecatApp', [
'ngRoute',
'phonecatControllers'
]);
phonecatApp.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/phones', {
templateUrl: 'partials/phone-list.html',
controller: 'PhoneListCtrl'
}).
when('/phones/:phoneId', {
templateUrl: 'partials/phone-detail.html',
controller: 'PhoneDetailCtrl'
}).
otherwise({
redirectTo: '/phones'
});
}]);controllers.js
'use strict';
/* Controllers */
var phonecatControllers = angular.module('phonecatControllers', []);
phonecatControllers.controller('PhoneListCtrl', ['$scope', '$http',
function($scope, $http) {
$http.get('phones/phones.json').success(function(data) {
$scope.phones = data;
});
$scope.orderProp = 'age';
}]);
phonecatControllers.controller('PhoneDetailCtrl', ['$scope', '$routeParams',
function($scope, $routeParams) {
$scope.phoneId = $routeParams.phoneId;
}]);bower.json
{
"name": "angular-phonecat",
"description": "A starter project for AngularJS",
"version": "0.0.0",
"homepage": "https://github.com/angular/angular-phonecat",
"license": "MIT",
"private": true,
"dependencies": {
"angular": "1.3.x",
"angular-mocks": "1.3.x",
"jquery": "~2.1.1",
"bootstrap": "~3.1.1",
"angular-route": "1.3.x"
}
}目前,我正在通过教程nro 7,其中包括路由。教程1-6没有使用路由,而且页面在Chrome上运行得很好。所以这个问题可能与路由有关。
任何帮助都将不胜感激。在此之前,非常感谢您。
发布于 2015-02-02 14:40:56
看起来,它为什么没有在Chrome上工作的问题不仅与浏览器有关,还与Node.js有关。本教程指示使用Node.js作为本教程的Web服务器,该教程在教程nro 7之前运行良好,该教程使用路由处理部分视图。现在看来,由于某种原因,当使用Node.js作为Web服务器时,Chrome上的路由无法工作。当我试图在Web服务器上使用Apache而不是Node.js时,我发现了这一点。在Apache上托管教程Web项目之后,路由在Chrome上开始正确运行。所以看起来这个问题与Chrome和Node.js有关。
我的Node.js版本是v0.10.33 (所以它不是最新版本)。
下面是Chrome的截图,网页托管在Apache上。

https://stackoverflow.com/questions/28253969
复制相似问题