1

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);
  };
});
1
  • Try using js2coffee.org to convert for you Commented Mar 27, 2014 at 1:04

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

10 Comments

same issue. Here is how I declare my controller angular.module("app").controller "ProductsController", ($scope, $http) -> It works fine with plain JS, bummer.
You'll want to get in the practice of named parameters for angular: module.controller("personList", ["$scope", "toolsService", 'idService', ($scope, tools, idService) -> ... etc ]) . I don't think that's the issue here. Can you put this up on plnkr.co? That's the easiest way to troubleshoot angular issues.
I cheated and grabbed an existing template, but I adapted it to your code: plnkr.co/edit/AzCz8SDpL23qujrp5dQs?p=preview -- in the future you should get in the practice of putting things like logging into a service instead of putting them on the rootscope. I use a toolsService that has lodash and my app config, for instance.
can you take a look to this Plunker as well plnkr.co/edit/itYnyzg2uS5xc6MJIIkE?p=preview I don't understand why customers not showing with this factory
plnkr.co/edit/cYasZTgxixoKVaJWB429?p=preview -- short answer: you were attempting to pass a function into factory.getCustomers when getCustomers did not exist. From factory.getCustomers -> to factory.getCustomers = ->
|
0
angular.module("app", [
  "ngResource"
  "ngRoute"
]).run ($rootScope) ->

You missed a comma here..

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

1 Comment

Nope, coffeescript will interpret same-level indents as separate items if they are in an array or function arg declaration. That compiles to: angular.module("app", ["ngResource", "ngRoute"]).run(function($rootScope) {});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.