1

我的数据正在从控制器显示。“ng-repeat”在显示数据时工作正常,但“ng-submit”没有使用以下代码向模型添加新数据:

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>
4

1 回答 1

2

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

于 2015-10-03T03:36:05.630 回答