I made angular app architecture like in other rails projects:
'use strict'
angular.module('BookReader.services', ['ngResource'])
angular.module('BookReader.directives', [])
angular.module('BookReader.controllers', ['ngCookies', 'ngRoute'])
BookReader = angular.module('BookReader', ['ngRoute', 'BookReader.controllers', 'BookReader.services', 'BookReader.directives'])
BookReader.config(['$routeProvider', '$httpProvider', '$locationProvider', ($routeProvider, $httpProvider, $locationProvider) ->
$routeProvider
.when '/',
templateUrl: 'view/tour.html'
controller: 'MainCtrl'
.when '/home',
templateUrl: 'view/main.html'
controller: 'HomeCtrl'
.when '/books',
templateUrl: 'view/books.html'
controller: 'BooksCtrl'
.otherwise
redirectTo: '/'
])
But it occurs error for all controllers. I tried different ways, but it only works in one file.
Argument 'MainCtrl' is not a function, got undefined
Chrome console:
Error: [ng:areq] http://errors.angularjs.org/undefined/ng/areq?p0=MainCtrl&p1=not%20a%20function%2C%20got%20undefined
at Error (<anonymous>)
at http://localhost:3000/assets/angular/angular.min.js?body=1:7:453
at qb (http://localhost:3000/assets/angular/angular.min.js?body=1:19:170)
at Ia (http://localhost:3000/assets/angular/angular.min.js?body=1:19:257)
at http://localhost:3000/assets/angular/angular.min.js?body=1:59:137
at http://localhost:3000/assets/angular-route/angular-route.min.js?body=1:8:9
at http://localhost:3000/assets/angular/angular.min.js?body=1:41:424
at s (http://localhost:3000/assets/angular-route/angular-route.min.js?body=1:7:378)
at h.$broadcast (http://localhost:3000/assets/angular/angular.min.js?body=1:108:417)
at http://localhost:3000/assets/angular-route/angular-route.min.js?body=1:11:443
MainCtrl
:
'use strict'
angular.module('BookReader.controllers', ['ngRoute', 'ngResource', 'ngCookies'])
.controller('MainCtrl', ['$scope', '$http', '$cookies', ($scope, $http, $cookies) ->
console.log("works")
])
Perhaps something changes in angular 1.2 version, or I can't see an obvious mistake.