【问题标题】:Using AngularJS inside Rails framework. "ng-repeat" is working, but "ng-submit" is not在 Rails 框架中使用 AngularJS。 “ng-repeat” 有效,但“ng-submit” 无效
【发布时间】:2015-10-03 11:36:05
【问题描述】:

我的数据正在从控制器显示。 “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>

【问题讨论】:

  • 是的,就是这样!如果您想回答“答案”部分中的问题,我会将其标记为正确。谢谢你这么快的回复。

标签: ruby-on-rails angularjs coffeescript ng-submit


【解决方案1】:

函数必须执行它,所以addEntry()应该解决它。

【讨论】:

    猜你喜欢
    • 2018-05-12
    • 1970-01-01
    • 2020-11-13
    • 2012-10-10
    • 1970-01-01
    • 1970-01-01
    • 2017-12-22
    • 1970-01-01
    • 2013-11-23
    相关资源
    最近更新 更多