[英]How to do a Survey Form to be submitted in angularjs
I want to submit a form in angularjs which are like survey, suppose user will fill the form and submit, I have array of all the questions of form, I want to update all the questions with the respected answers by iterating all the questions from array and update each question individually(why because I only have API to update one question)
我想在angularjs中提交一个类似于调查的表单,假设用户将填写该表单并提交,我拥有表单中所有问题的数组,我想通过迭代数组中的所有问题来更新所有问题并获得尊敬的答案并分别更新每个问题(为什么因为我只有API来更新一个问题)
This is my form
这是我的表格
<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);
});
});
}
not getting values from this surveydataforparticipate function.
无法从此surveydataforparticipate函数获取值。 also Is it correct that i have put foreach to submit the data using $http?
我放foreach使用$ http提交数据也是正确的吗?
Thanks for helping.
感谢您的帮助。
You can define a function in your controller
where the form should go on submit
. 您可以在
controller
中定义一个函数,以便表单继续submit
。 And, use ng-submit
to link that function to your form. 并且,使用
ng-submit
将该功能链接到您的表单。
<ng-form name="participateSurveyForm" ng-submit="submitForm ()" novalidate>
In your controller : 在您的控制器中:
$scope.submitForm = function(){
//definition of the function.
//access form data here.
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.