我在index.html中包含其他html文件作为模板。为此我使用ng-view指令。但我收到一个错误:
Unknown provider: $templateRequestProvider <- $templateRequest <- $route <- ngViewDirective
我正在使用的代码是:
'use strict';
var surveyApp = angular.module('surveyApp',['ngRoute']);
surveyApp.factory('surveyFactory',function (){
return {}
});
以下是控制器:
surveyApp.controller('profileController', function($scope,surveyFactory) {
// create a message to display in our view
$scope.message = 'This is the profile page';
});
surveyApp.controller('surveysController', function($scope,surveyFactory) {
// create a message to display in our view
$scope.message = 'This is the surveys page';
});
配置:
surveyApp.config(function($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl : 'pages/profile.html',
controller : 'profileController'
})
.when('/surveys', {
templateUrl : 'pages/surveys.html',
controller : 'surveysController'
});
$locationProvider.html5Mode(true);
});
这是HTML:
<body ng-app="surveyApp">
<div id="main">
<div ng-view></div>
</div>
</body>
我在哪里错过了?
答案 0 :(得分:41)
完成。在大多数情况下,角度路线的versions
和角度是相互矛盾的。之后,由于
.when('/', {
templateUrl : 'pages/profile.html',
controller : 'profileController'
})
每次看到'/'时,它都会重新定向到同一页面,从而形成无限重定向循环。这应该在最后使用,以便检查第一个,如果仍然存在,那么它会看到'/'路径。
答案 1 :(得分:4)
有同样的问题,对我来说问题也是一种依赖,但不是角度路线。导致错误的依赖性是angular-bootstrap。
我们项目中的当前角度版本是1.28,角度路线也是1.28。将angular-bootstrap从0.12.1更新为0.13时触发此错误。
答案 2 :(得分:1)
您的代码唯一的问题是surveyFactory
定义后缺少结束大括号。
将应用和工厂定义的代码更改为以下解决问题:
var surveyApp = angular.module('surveyApp',['ngRoute']);
surveyApp.factory('surveyFactory',function (){
return {}
});