简体   繁体   English

Angular Coffeescript语法错误

[英]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 尝试在我的角度应用程序中将工作的JS转换为coffee脚本,但会引发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 下面的js工作正常

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

Your indents are off. 您的缩进不正确。 Coffeescript is whitespace aware. Coffeescript具有空格意识。

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. 这并不能解释为什么ContactController无法被加载,但是如果您的模块定义不正确,就可以解释它。

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

You missed a comma here.. 您在这里错过了逗号。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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