0

I have an angular app using ngRoute when I declare controller normally it doesn't work correctly becault of implicit return of coffeescript so I use this solution but this time I get this error:

Error: [ng:areq] Argument 'BarsController' is not a function, got undefined

simplified version of myApp:

angule.module('app',['ngRoute'])
.config(($routeProvider)->
  $routeProvider.when('/bar',
    templateUrl:'bar/bars.html'
    controller:'BarsController'
    controllerAs:'bc'
  )
)
angular.module('app').controller('BarsController',['$scope','$resource',BarsCtrl])
class BarsCtrl
  constructor:($scope,$resource)->
    console.log "in controller"

1 Answer 1

2

In the same link you provide, it suggests to put the controller definition last:

angule.module('app',['ngRoute'])
.config(($routeProvider)->
  $routeProvider.when('/bar',
    templateUrl:'bar/bars.html'
    controller:'BarsController'
    controllerAs:'bc'
  )
)

class BarsCtrl
  constructor:($scope,$resource)->
    console.log "in controller"

angular.module('app').controller('BarsController',['$scope','$resource',BarsCtrl])
Sign up to request clarification or add additional context in comments.

Comments

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.