As I work on managing and refactoring my Angular code in a Rails project with CoffeeScript, I am facing issues accessing Angular objects between multiple files. Here is the current file structure:
javascripts
|-Angular
|-controllers
| |-search_strl.js.coffee
|-main.js.coffee
|-application.js
In application.js: //= require_tree ./angular
In main.js.coffee:
'use strict';
copassApp = angular.module 'copassApp', []
In search_ctrl:
copassApp.controller('SearchCtrl', ['$scope', 'Cospace', 'Copasser', '$location', ($scope, Cospace, Copasser, $location) -> ...more code...
Console error: Uncaught ReferenceError: copassApp is not defined
I'm unsure if this issue stems from a missing required file or a problem with how I've structured my Angular module and CoffeeScript setup across files. Any guidance would be appreciated.
Edit
After implementing the suggested solution, here is the compiled JS:
main.js.coffee:
(function() {
'use strict';
var copassApp, root;
copassApp = angular.module('copassApp', ['copassApp.SearchCtrl']);
root = $('html');
angular.bootstrap(root, ['copassApp']);
}).call(this);
search_strl.js.coffee:
(function() {
angular.module('copassApp.SearchCtrl', ['$scope', 'Cospace', 'Copasser', '$location', function($scope, Cospace, Copasser, $location) {}]);
}).call(this);