表单中的Angular JS多输入

时间:2014-09-08 10:52:25

标签: ruby-on-rails angularjs

是否有任何理由不将多个输入从Angular表单传递给控制器​​。其中一个输入将提交。问题是他们都不能以同样的形式提交。

<form name="myForm" ng-controller="PostIndexCtrl" class="my-form">
        <input type='text' ng-model="entry.question_id" name="question_id" value="1">
        <input type='text' ng-model="entry.answer" name="answer"><br/>
        <button class="btn btn-primary" ng-click="saveEntry()">Save</button>
    </form>

这是控制器

.controller("PostIndexCtrl", function($scope, Post, $resource, $http) {

    Post.query(function(data) {
        $scope.posts = data;
    });

    var data = $resource('/api/answers/', {answer: '@answer', question_id: '@question_id'});

    $scope.saveEntry = function() {
        data.save($scope.entry);
    }

});

0 个答案:

没有答案