2016-12-11 16 views
0

に提出する調査票を行うにはどのように、 ユーザーがフォームを記入して提出すると仮定し、私は、フォームのすべての質問 の配列を持っています私は、これは私は調査のようなものangularjsでフォームを送信したい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); 
}); 
}); 

} 

このsurveydataの参加機能から値を取得できません。また 私は$ httpを使用してデータを提出するためにforeachを置いたのは正しいですか?

ありがとうございます。

+0

は、私はあなたが 'optionofanswer'と' optionforanswer'を混同だと思います。そういうわけで、あなたは '未定義 'になっています。それを修正して、あなたは行かなくてはなりません。 – georgeawg

答えて

0

には、submitという形式で関数を定義できます。そして、その関数をフォームにリンクするにはng-submitを使用します。お使いのコントローラで

<ng-form name="participateSurveyForm" ng-submit="submitForm()" novalidate> 

$scope.submitForm = function(){ 
//definition of the function. 
//access form data here. 
} 
+0

それでも、$ scopeを使用しているフォームの値が未定義になっていません。 – Kranthi

+0

どのように値を取得しようとしていますか?見せてもらえますか? –

関連する問題