2014-06-06 5 views
2

나는 사용자가 대답해야하는 질문 목록을 가지고 있습니다. 그 때문에 양식을 준비했습니다.각도 js에서 textArea의 양방향 바인딩

HTML 양식은 사용자가 내가 코멘트 사용자가 모든 질문을 올렸습니다 받아야 양식을 제출할 때

<div class="list" ng-repeat="question in questions.data.Question" > 
     <div class="item item-divider"> 
     {{question.text}} 
    </div> 
    <label class="item item-input" ng-if="question.type =='comment'"> 
     <textarea placeholder="Comments"></textarea> 
    </label> 
</div> 

지금 내 JSON 문자열 지금

{ 
    "sucess": true, 
    "message": "record(s) fetched sucessfully", 
    "data": { 
     "Question": [ 
      { 
       "id": "4", 
       "text": "how was it?", 
       "type": "comment" 
      }, 
      { 
       "id": "6", 
       "text": "how was it?", 
       "type": "comment" 
      } 
     ] 
    } 
} 

입니다.

+2

귀하의 질문은 무엇입니까? 작동하지 않는 것은 무엇입니까? 너 뭐 해봤 니? – StuR

+0

제출 버튼을 클릭 할 때 모든 질문에 대해 사용자가 게시 한 답변을 원합니다. – Aks

답변

5

나는 전문가는 아니지만, ng-model을 textarea 요소에 추가해야한다고 생각합니다.

<div class="list" ng-repeat="question in questions.data.Question" > 
     <div class="item item-divider"> 
      {{question.text}} 
     </div> 
     <label class="item item-input" ng-if="question.type =='comment'"> 
      <textarea placeholder="Comments" ng-model="question.comments"></textarea> 
     </label> 
</div> 

각 댓글 유형 질문에 '의견'입력란을 추가해야합니다. 예 : 당신이있을 경우 "의견"필드를 추가 할 필요가 있습니다

 { 
      "id": "6", 
      "text": "how was it?", 
      "type": "comment", 
      "comments": "" 

     } 

주 내가 잘 모르는 것 같아요 AngularJS와 대한 플래그 '힘은 필드를 추가'.

+0

동일한 서비스가 아닌 다른 모델에 게시하고 싶습니다 – Aks

+0

이 제출 버튼은 무엇을합니까? 양식을 제출 하시겠습니까? 해당 양식에 ng-submit 지시문을 추가 했습니까? 사용자가 게시 한 모든 설명을 제출하려면 컨트롤러에서 ng-submit 호출 기능의 모델을 전송해야합니다. 모델은 변경 한 DOM 요소를 변경하면 자동으로 업데이트됩니다. – holgac

+0

버튼을 클릭하지 않고 모델을 전달하는 함수를 호출했습니다 – Aks

4

ng-model을 텍스트 영역에 바인딩해야합니다. 초기 json 데이터에 "answer"변수가 없더라도 작동합니다. 데모 용 버튼을 추가했습니다. 전체 예제보기 JSFIDDLE

<div id="qApp" ng-controller="qAppCntrl"> 
<div class="list" ng-repeat="question in questions.data.Question track by $index" > 
    <div class="item item-divider"> 
    {{question.text}} 
    </div> 
    <label class="item item-input" ng-if="question.type =='comment'"> 
    <textarea placeholder="Comments" ng-model="question.answer"></textarea> 
    </label> 
</div> 
<button ng-click="submit()">Post</button> 
</div>