Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
200 views
in Technique[技术] by (71.8m points)

javascript - Angularjs unknown provider in $templateRequestProvider

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...