我想在angularjs中提交一个类似调查的表格,假设 用户将填写表格并提交,我有所有问题的数组 形式,我想用尊重的答案更新所有问题 通过迭代数组中的所有问题并更新每个问题 个别(为什么因为我只有API来更新一个问题)
这是我的表格
<ng-form name="participateSurveyForm" novalidate>
<div class="form_fields_survey_audience" ng-repeat="questionlistitem in surveyquestiondata">
<h3 class="">{{questionlistitem.question}}</h3>
<div ng-show="questionlistitem.question_type == 'multiple_choice'">
<div class="radio" ng-repeat="optionofanswers in questionlistitem.options">
<div class="form-group">
<label>
<input type="radio" name="optionforanswer" ng-model="surveydataforparticipate.optionforanswer" ng-value="optionofanswers.option" required checked>{{optionofanswers.option}}
</label>
</div>
</div>
</div>
<div ng-show="questionlistitem.question_type == 'open_text'">
<div class="form-group" >
<textarea class="textAreaMultiligne" name="open_text_field" ng-model="surveydataforparticipate.open_text_field" required placeholder="Answer Here" rows="10" cols="40"></textarea>
</div>
</div>
</div> <!--End Row-->
<div class="row">
<div class="col-lg-12">
<button type="submit" ng-click="participateInSurvey(surveydataforparticipate)" class="btn btn-primary">Complete</button>
</div>
</div><!--row & Submit Button-->
</ng-form>
//Anguar Code
$scope.participateInSurvey = function(surveydataforparticipate){
angular.foreach(surveydataforparticipate, function(value){
$http.put('/api/survey/question/+value._id, surveydataforparticipate).success(function(data){
console.log(data);
});
});
}
没有获得此观察参与功能的值。也 我使用$ http提交数据是正确的吗?
感谢您的帮助。
答案 0 :(得分:0)
您可以在controller
中定义一个功能,其中表单应该在submit
上。并且,使用ng-submit
将该功能与您的表单相关联。
<ng-form name="participateSurveyForm" ng-submit="submitForm ()" novalidate>
在您的控制器中:
$scope.submitForm = function(){
//definition of the function.
//access form data here.
}