1

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>
Community
  • 1
  • 1
Ctpelnar1988
  • 1,235
  • 3
  • 15
  • 38
  • Yes, that was exactly it! If you would like to answer the question in the "answer" section I will mark it as correct. Thank you for such a quick response. – Ctpelnar1988 Oct 03 '15 at 03:35

1 Answers1

2

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

YOU
  • 120,166
  • 34
  • 186
  • 219