简体   繁体   中英

Angular coffeescript syntax error

Trying to convert working JS to coffee script in my angular app but its raises Error: [ng:areq] Argument 'ContactController' is not a function, got undefined

Here is my code.

angular.module("app", [
  "ngResource"
  "ngRoute"
]).run ($rootScope) ->

$rootScope.log = (thing) ->
console.log thing

The following js works fine

angular.module("app", ["ngResource", "ngRoute"]).run(function($rootScope) {
  $rootScope.log = function(thing) {
    console.log(thing);
  };
});

Your indents are off. Coffeescript is whitespace aware.

angular.module("app", [
  "ngResource"
  "ngRoute"
]).run ($rootScope) ->    
  $rootScope.log = (thing) ->
    console.log thing

Becomes:

angular.module("app", [ "ngResource", "ngRoute" ]).run ($rootScope) ->
  $rootScope.log = (thing) ->
    console.log thing

This doesn't explain why ContactController wouldn't be loading, but if your module isn't being defined correctly that could explain it.

angular.module("app", [
  "ngResource"
  "ngRoute"
]).run ($rootScope) ->

You missed a comma here..

angular.module("app", [
  "ngResource",
  "ngRoute"
]).run ($rootScope) ->

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM