是否有任何理由不将多个输入从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);
}
});