У меня есть форма с ng-model="award.myProperty"
. Есть некоторые входы и texareas. В моем сервисе у меня есть массив для textareas:
allQuestions = [
id: 'XXX', question: 'some text',
id: 'YYY', question: 'some text',
id: 'ZZZ', question: 'some text',
];
Моя цель - получить данные из текстовых областей в такой структуре
questions: [{
'XXX': 'data from textarea1',
'YYY': 'data from texarea2',
'ZZZ': 'data from textarea3',
}];
Я пытался использовать ng-repeat с ng-model
, но ng-model
не возвращает идентификаторы. Если я использую $index
с ng-repeat
, тогда я получаю массив:
[{ 0: 'data from textarea1',
1: 'data from textarea2',
2: 'data from textarea3',}]
Структура хорошая, но это не мой идентификатор из сервиса.
СЕРВИС
const allQuestions = [
{ id: 'XXX', question: 'question1' },
{ id: 'YYY', question: 'question2' },
{ id: 'ZZZ', question: 'question3' },
];
getQuestion() {
return allQuestions;
},
CONTROLLER
$scope.allQuestions = awards_service.getQuestion();
$scope.award = {
description: '',
questions: [],
};
VIEW
<form name="awardForm">
<input ng-model="award.description"></input>
<div ng-repeat="question in allQuestions">
<textarea ng-model="award.questions"></textarea>
</div>
</form>
Может быть, есть лучшее решение, чем ng-repeat
.