Search code examples
ruby-on-railsangularjscoffeescriptng-submit

Using AngularJS inside Rails framework. "ng-repeat" is working, but "ng-submit" is not


My data is being displayed from the controller. "ng-repeat" works fine when displaying the data, but "ng-submit" is not adding new data to the model using the following code:

pages.js.coffee

  @PagesController = ($scope) ->
   $scope.entries = [
     {name:"Larry"}
     {name:"Curly"}
     {name:"Mo"}
     {name:"Ralph"}
    ]

    $scope.addEntry = ->
     $scope.entries.push($scope.newEntry)
     $scope.newEntry = {}

index.html.erb

  <div ng-controller="PagesController">


    <h1>Angular & Rails</h1>

    <form ng-submit="addEntry">
      <input type="text" ng-model="newEntry.name">
      <input type="submit" value="Add">
    </form>

    <ul>
      <li ng-repeat="entry in entries">
        {{entry.name}}
      </li>
    </ul>

   </div>

Solution

  • function have to execute it, so addEntry() should solve it.