我在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>
我在哪裏錯過?
您是否添加了angular-route.js文件? – 2014-10-06 10:34:01
是的。我已經添加了angular-route.min.js文件,它加載了任何缺少的腳本,並且沒有任何錯誤。 – Shikhar 2014-10-06 10:38:10