Reputation: 2639
I have defined a angular app module as below
var dashboardApp = angular.module('dashboardApp', []);
It works fine, but when I rewrite this module in coffeescript, angular report a error
dashboardApp is not defined
The coffeescript code is :
dashboardApp = angular.module 'dashboardApp', []
I know the when wring in coffeescript, all variable is automatically wrapped to avoid polluting global scope.
So the question is: Does this mean angular require module to be defined in global scope? is it possible to use coffeescript to define the module?
The accurate error message is
Uncaught ReferenceError: dashboardApp is not defined
I got this error because I use dashboardApp to create controller and service like this in other files:
dashboardApp.factory 'Utility', ->
Utility = {}
Utility.imageValidator = (file, max_size,allowed_type) ->
file_type = file.type
file_size = file.size
result = true
result = false if file_size > max_size
result = false if ( allowed_type.indexOf(file_type) is -1)
result
Utility
Upvotes: 0
Views: 383
Reputation: 861
The error you're experiencing is a JavaScript error, not an Angular one. You have a couple options.
I suggest the module dependency pattern as it explicitly shows what modules depend on what other functionality.
dashboardApp = angular.module 'dashboardApp', ['dashboardApp.factories']
dashboardAppFactories = angular.module 'dashboardAppFactories, []
dashboardAppFactories.factory 'Utility' , => ...
Upvotes: 1