$templateRequestProvider 中的 Angularjs 未知提供者 [英] Angularjs unknown provider in $templateRequestProvider

查看:24
本文介绍了$templateRequestProvider 中的 Angularjs 未知提供者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 index.html 中包含其他 html 文件作为模板.为此,我正在使用 ng-view 指令.但我收到一个错误:未知提供者:$templateRequestProvider <- $templateRequest <- $route <- ngViewDirective我使用的代码是:

'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:

<div id="main"><div ng-view></div>

我错过了什么?

解决方案

完成.在大多数情况下,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 未知提供者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆