2路的角度JS textarea的结合 [英] 2-way binding of textArea in angular js

查看:106
本文介绍了2路的角度JS textarea的结合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题的列表,用户必须answer.For一个有prepared一种形式。

I have a list of question that user has to answer.For that a have prepared a form.

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字符串为

now my json string is

{
    "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"
            }
        ]
    }
 }

现在,当用户提交表单我应该得到的评论用户发布的所有问题。

now when user submit the form I should get the comment user has posted of all the question.

推荐答案

您必须NG-模式绑定到textarea的,它的工作原理,即使你没有在初始JSON数据的答案的变量。我已经加入了演示目的的按钮。在的jsfiddle

You have to bind ng-model to the textarea, it works even if you don't have the "answer" variable in your initial json data. I have added a button for demo purpose. Full example on 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>

这篇关于2路的角度JS textarea的结合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆