我有一个用户必须回答的问题列表。为此准备了一个表格。
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"
}
]
}
}
现在,当用户提交表单时,我应该得到用户发布的所有问题的评论。
最佳答案
您必须将 ng-model 绑定(bind)到 textarea,即使您的初始 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>
关于javascript - angular js中textArea的2路绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24079505/