我已经在index.html页面中添加了angular-route.js
。
<script type = "text/javascript" src = "bower_components/angular/angular.js"></script>
<script type="text/javascript" src="bower_components/angular-route/angular-route.js"></script>
<script type="text/javascript" src="bower_components/oclazyload/dist/ocLazyLoad.min.js"></script>
<script type = "text/javascript" src = "public/app/appRoutes.js"></script>
appRoutes.js:
angular.module('appRoutes', ['ngRoute', 'oc.lazyLoad']).config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl: 'app/components/in-progress/in-progress.template.html',
controller: 'inProgressController',
resolve: {
lazy: ['$ocLazyLoad', function($ocLazyLoad) {
return $ocLazyLoad.load({files: ['app/components/in-progress/in-progress.component.js']});
}]
}
})
.... different routes
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
}]);
我不明白,为什么由于$routeProvider
导致失败,即使我采取了所有可能的预防措施。
我也在我的主应用程序中添加了ng-route
。
Angular版本:1.5
答案 0 :(得分:0)
您的代码缺少'ngInject'。这是阵列注入后通常需要的。尝试添加它......
angular.module('appRoutes', ['ngRoute', 'oc.lazyLoad']).config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
'ngInject';
$routeProvider
.when('/', {
templateUrl: 'app/components/in-progress/in-progress.template.html',
controller: 'inProgressController',
resolve: {
lazy: ['$ocLazyLoad', function($ocLazyLoad) {
return $ocLazyLoad.load({files: ['app/components/in-progress/in-progress.component.js']});
}]
}
})
.... different routes
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
}]);