Angularjs $ templateRequestProvider中的未知提供程序

Shi*_*har 24 javascript angularjs angularjs-directive

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

'use strict';
 var surveyApp = angular.module('surveyApp',['ngRoute']);
    surveyApp.factory('surveyFactory',function (){
 return {}
});
Run Code Online (Sandbox Code Playgroud)

以下是控制器:

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';
});
Run Code Online (Sandbox Code Playgroud)

配置:

surveyApp.config(function($routeProvider, $locationProvider) {
$routeProvider
    .when('/', {    
        templateUrl : 'pages/profile.html',
        controller  : 'profileController'
    })

    .when('/surveys', {
        templateUrl : 'pages/surveys.html',
        controller  : 'surveysController'
    });
$locationProvider.html5Mode(true);
});
Run Code Online (Sandbox Code Playgroud)

这是HTML:

<body ng-app="surveyApp">
    <div id="main">
        <div ng-view></div>
    </div>
</body>
Run Code Online (Sandbox Code Playgroud)

我在哪里错过了?

Shi*_*har 41

完成.在大多数情况下,它将是versions角度路线,而角度是相互矛盾的.之后,由于连续的循环请求,它主要使页面崩溃

.when('/', {    
    templateUrl : 'pages/profile.html',
    controller  : 'profileController'
})
Run Code Online (Sandbox Code Playgroud)

每次看到'/'时,它都会重新定向到同一页面,从而形成无限重定向循环.这应该在最后使用,以便检查第一个,如果仍然存在,那么它会看到'/'路由.

  • 尝试Angular 1.3后我遇到了这个错误 - 即使在安装了凉亭之后,角度路由1.3也得到了服务.凉亭安装-f固定了. (6认同)