我使用3個嵌套的ng-repeat讀取json並顯示幾個問題和他的答案。直到這裏工作,但現在我試圖存儲選擇的答案並將其發送到API。我不知道爲什麼選擇的答案沒有被存儲。AngularJS:從表單中獲取值
這是我的看法:
<form>
<div class="panel panel-default" ng-repeat="section in questionsTest">
<div class="panel-heading">
<h1>{{ section.name }}</h1>
<h3 class="panel-title">{{ section.name }}. {{
section.description }}</h3>
</div>
<div class="panel-body" ng-repeat="question in section.questions">
{{ question.statement }}
<div ng-repeat="answer in question.answers">
<!-- <label class="radio-inline"> <input type="{{ answer.type }}" ng-model="question.value"
name="{{ answer.id }}" id="{{ answer.id }}" value="{{ answer.id }}">
{{ answer.valor }}
</label>-->
<label class="radio-inline"> <input type="{{ answer.type }}" ng-model="question.valor"
name="{{ question.id }}" id="{{ answer.id }}" value="{{ answer.id }}">
{{ answer.valor }}
</label>
</div>
</div>
</div>
</form>
這是控制器:
$scope.question = {};
$scope.testing = function(){
console.log($scope.question);
};
$ scope.testing是一個測試功能,在控制檯上看到的$ scope.question
值
你可以把一個plunker? –
是@Maximus它在這裏:https://plnkr.co/edit/m35iYTFdh3G5v3IRghRI?p=preview – proktovief
請參閱[我的答案](http://stackoverflow.com/a/41525688/2545680) –