Javascript $templateRequestProvider 中的 Angularjs 未知提供程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26213627/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Angularjs unknown provider in $templateRequestProvider
提问by Shikhar
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 <- ngViewDirectiveThe code I am using is:
我在 index.html 中包含其他 html 文件作为模板。为此,我正在使用 ng-view 指令。但我收到一个错误:
Unknown provider: $templateRequestProvider <- $templateRequest <- $route <- ngViewDirective我使用的代码是:
'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:
这是 HTML:
<body ng-app="surveyApp">
<div id="main">
<div ng-view></div>
</div>
</body>
Where am I missing?
我在哪里失踪?
回答by Shikhar
Done. In most of the cases it would be the versionsof angular-route and angularjs were conflicting. After then, it mostly crashed the page due to continuous loop requests in
完毕。在大多数情况下versions,angular-route 和 angularjs 会发生冲突。之后,由于连续的循环请求,它主要使页面崩溃
.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.
每次看到“/”时,它都会重新重定向到同一页面,从而形成一个无限重定向循环。这应该在最后使用,以便检查第一个,如果仍然存在,那么它会看到 '/' 路由。
回答by Millenjo
Had the same problem, the issue for me was also a dependancy but not angular-route. The dependancy that caused the error for me was angular-bootstrap.
有同样的问题,对我来说问题也是依赖而不是角度路线。对我来说导致错误的依赖是 angular-bootstrap。
The current angular version in our project is 1.28 and angular-route is also 1.28. This error was triggered on updating angular-bootstrap from 0.12.1 to 0.13.
我们项目中的当前 angular 版本是 1.28,angular-route 也是 1.28。此错误是在将 angular-bootstrap 从 0.12.1 更新到 0.13 时触发的。
回答by Aditya Singh
The only issue with your code is the missing closing curly brace after surveyFactorydefinition.
您的代码的唯一问题是surveyFactory定义后缺少右花括号。
Change the code for app and factory definition to below to fix the issue:
将应用程序和工厂定义的代码更改为以下以解决问题:
var surveyApp = angular.module('surveyApp',['ngRoute']);
surveyApp.factory('surveyFactory',function (){
return {}
});

