问题描述
我在 index.html 中包含其他 html 文件作为模板.为此,我正在使用 ng-view 指令.但我收到一个错误:未知提供者:$templateRequestProvider 我使用的代码是:
'use strict';var SurveyApp = angular.module('surveyApp',['ngRoute']);surveyApp.factory('surveyFactory',function(){返回 {}});
这里是控制器:
surveyApp.controller('profileController', function($scope,surveyFactory) {//创建一条消息显示在我们的视图中$scope.message = '这是个人资料页面';});SurveyApp.controller('surveysController', function($scope,surveyFactory) {//创建一条消息显示在我们的视图中$scope.message = '这是调查页面';});
配置:
surveyApp.config(function($routeProvider, $locationProvider) {$routeProvider.什么时候('/', {templateUrl : 'pages/profile.html',控制器:'配置文件控制器'}).when('/调查', {templateUrl : 'pages/surveys.html',控制器:'调查控制器'});$locationProvider.html5Mode(true);});
这是 HTML:
我错过了什么?
完成.在大多数情况下,angular-route 和 angularjs 的 versions
会发生冲突.之后,它主要是由于
.when('/', {templateUrl : 'pages/profile.html',控制器:'配置文件控制器'})
每次看到'/',它都会重新重定向到同一个页面,从而形成一个无限重定向循环.这应该在最后使用,以便检查第一个,如果还有一些东西,那么它会看到 '/' 路由.
I am including other html files as template in index.html. For this i am using ng-view directive. But i am getting an error: Unknown provider: $templateRequestProvider <- $templateRequest <- $route <- ngViewDirective
The code I am using is:
'use strict';
var surveyApp = angular.module('surveyApp',['ngRoute']);
surveyApp.factory('surveyFactory',function (){
return {}
});
Here are the Controllers :
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';
});
The Config:
surveyApp.config(function($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl : 'pages/profile.html',
controller : 'profileController'
})
.when('/surveys', {
templateUrl : 'pages/surveys.html',
controller : 'surveysController'
});
$locationProvider.html5Mode(true);
});
This is the HTML:
<body ng-app="surveyApp">
<div id="main">
<div ng-view></div>
</div>
</body>
Where am I missing?
Done. In most of the cases it would be the versions
of angular-route and angularjs were conflicting. After then, it mostly crashed the page due to continuous loop requests in
.when('/', {
templateUrl : 'pages/profile.html',
controller : 'profileController'
})
Every time it saw a '/', it redirected to the same page all over again and hence forming an infinite redirect loop. This should be used in the last so that the first ones are checked, and if something remains, then it sees the '/' route.
这篇关于$templateRequestProvider 中的 Angularjs 未知提供程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!