javascript - Angular JS on Rails - Argument 'RaffleCtrl' is not a function, got undefined -


i'm following tutorial integer angular js on ror project.

in controller js files i've got this:

raffle.coffee

# place behaviors , hooks related matching controller here. # logic automatically available in application.js. # can use coffeescript in file: http://coffeescript.org/  @rafflectrl = ($scope) ->     $scope.entries = [            {name:"name1"}         {name:"name2"}         {name:"name3"}         {name:"name4"}     ]  

and in controller html (generated rails) i've got this:

index.html.erb

<h1>raffle</h1>  <div ng-controller="rafflectrl">     <form>         <input type="text" ng-model="newentry.name">     </form>      <ul>         <li ng-repeat="entry in entries">             {{entry.name}}         </li>     </ul> </div> 

so should repeat 4 name in array entries doesn't work: open log , found error:

argument 'rafflectrl' not function, got undefined

add app name in application.html.erb:

<html ng-app="raffler"> ... </html> 

in raffle.js.coffee replace this:

@rafflectrl = ($scope) -> 

with this:

angular.module('raffler', []).controller "rafflectrl", ($scope) -> 

give application module name, , make sure ng-app attribute set same name, "raffler" in case, in application layout.

while i'm not yet myself why other differences in syntax defining controller name solved problem, did solve problem in case. using rails '4.1.5' , angularjs-rails gem 1.4.4.

credit mederic de launay


Comments