Пытаюсь при каждой загрузке страницы загружать нужный для нее контроллер через LazyLoad. Мой код:
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body ng-app="Arenda" ng-controller="RootController">
<div ui-view="navBar" class="animate-hide" ng-hide="navBarHide"></div>
<div ui-view="bgPageHeader" class="animate-if" ng-hide="bgPageHeaderHide"></div>
<div ui-view></div>
<script src=bower_components/jquery/dist/jquery.min.js></script>
<!-- angularjs -->
<script src="bower_components/angular/angular.min.js"></script>
<script src="bower_components/angular-sanitize/angular-sanitize.min.js"></script>
<script src="bower_components/angular-animate/angular-animate.min.js"></script>
<script src="bower_components/angular-aria/angular-aria.min.js"></script>
<script src="bower_components/angular-messages/angular-messages.min.js"></script>
<!-- ui-router -->
<script src="bower_components/angular-ui-router/release/angular-ui-router.min.js"></script>
<!-- ocLazyLoad -->
<script src="bower_components/oclazyload/dist/ocLazyLoad.min.js"></script>
<!-- angular material -->
<script src="bower_components/angular-material/angular-material.min.js"></script>
<!-- app -->
<script src="js/angular/init.js"></script>
<script src="js/angular/states.js"></script>
<script src="js/angular/ocLazyLoad.js"></script>
</body>
</html>
js/init.coffee
app = angular.module "Arenda", [
'ngMaterial'
'ui.router'
'oc.lazyLoad'
'ngSanitize'
'ngAnimate'
] # module init
app.run [
'$rootScope'
($rootScope) ->
# some code here
js/states.coffee
app.
config [ # config
'$stateProvider'
'$urlRouterProvider'
($stateProvider, $urlRouterProvider) ->
$urlRouterProvider
.otherwise '/' # редирект, если роут не найден
$stateProvider # правида
# restricted
.state "restricted",
abstract: true
url: ""
views:
navBar:
templateUrl: 'shared/navbar.html'
"bgPageHeader":
templateUrl: 'shared/bg-pageheader.html'
"":
template: "<div ui-view></div>"
resolve:
deps: ['$ocLazyLoad', ($ocLazyLoad) ->
$ocLazyLoad.load [
"bootstrap"
],{ serie: true }
]
.state "restricted.landing",
url: "/"
controller: 'RoomController'
templateUrl: "shared/rooms.html"
resolve:
deps: ['$ocLazyLoad', ($ocLazyLoad) ->
$ocLazyLoad.load [
"js/angular/controllers/RoomController.js"
],{ serie: true }
]
return
]
js/ocLazyLoad.coffee
app.
config [
'$ocLazyLoadProvider'
($ocLazyLoadProvider) ->
$ocLazyLoadProvider.config
debug: true
events: false
modules: [
{
name: 'bootstrap'
files: [
'bower_components/tether/dist/js/tether.min.js'
'js/bootstrap.min.js'
'css/bootstrap.min.css'
'css/style.css'
'bower_components/angular-material/angular-material.min.css' # angular material
'https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css' # font awesome
]
serie: true
}
]
]
код RoomController'а я приводить не буду, т.к. его очень много, но смысл в том, что если я перенесу его в init.coffee, то все работает как нужно.
Но всегда получаю Exception в браузере
Error: [ng:areq] http://errors.angularjs.org/1.5.0/ng/areq?p0=RoomController&p1=not%20aNaNunction%2C%20got%20undefined
at Error (native)
at http://localhost:63342/arenda/bower_components/angular/angular.min.js:6:416
at sb (http://localhost:63342/arenda/bower_components/angular/angular.min.js:23:63)
at Sa (http://localhost:63342/arenda/bower_components/angular/angular.min.js:23:150)
at http://localhost:63342/arenda/bower_components/angular/angular.min.js:86:318
at http://localhost:63342/arenda/bower_components/angular-ui-router/release/angular-ui-router.min.js:1:32868
at ka (http://localhost:63342/arenda/bower_components/angular/angular.min.js:79:16)
at u (http://localhost:63342/arenda/bower_components/angular/angular.min.js:66:326)
at g (http://localhost:63342/arenda/bower_components/angular/angular.min.js:58:136)
at http://localhost:63342/arenda/bower_components/angular/angular.min.js:57:279
Такая картина во вкладке F12 -> Network
Почему то здесь ->
http://altair_app.tzdthemes.com/ приложение с такой же архитектурой работает, я видимо что то пропустил.