zishe zishe - 5 months ago 24
CoffeeScript Question

AngularJS express coffee-assets controller not found

In my AngularJS node.js app based on angular-express-blog and express-coffee I have an issue with defenition

before controllers pic:

Uncaught ReferenceError: IndexCtrl is not defined

The order of including modules the same as in angular-seed:

// JS
!= js('lib/jquery-1.7.2.min.js')
!= js('lib/bootstrap.min.js')
!= js('lib/angular.min.js')

!= js('app')
!= js('controllers')
!= js('directives')
!= js('filters')
!= js('services')

After change order to this:

!= js('controllers')
!= js('app')
!= js('directives')
!= js('filters')
!= js('services')

Error the same. It works only when I replace controllers to app.coffee before
defenition. I restarted server of course.

Update: app file, controller file and layout

Answer Source

In Coffeescript, compiled things are wrapped in a closure:

(function() { function MyController($scope) {} })();

Now index.html can't find the MyController variable because it's in a closure!

Use the module.controller syntax instead.

angular.module('myApp').controller 'MyController', ($scope) ->

This will cause your controller to be visible everywhere.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download