を選択することができますこの方法で、あなたが持っている可能性があり表示するすべてのオプションを持つ配列と、空になり、ビューにフィードする配列。ユーザーがオプションを選択すると、新しいステップが2番目の配列にプッシュされます。
コントローラ
function OptionsCtrl($scope) {
$scope.options = [
{text:'learn angular', select:['option1', 'option2', 'option3']},
{text:'build an angular app', select:['another1', 'another2', 'another3', 'another4']},
{text:'build an angular app', select:['onemore1', 'onemore2']}
];
$scope.showNextOption = function(){
var nextIndex = $scope.visibleOptions.length;
if($scope.options.length > nextIndex)
{
$scope.results.push({input:'',select:''});
$scope.visibleOptions.push($scope.options[nextIndex]);
}else{
// you can call $scope.save() here if you wish to save when the options have been presented
// or just use the save button
console.log('save');
}
};
$scope.save = function() {
//do whatever you need with $scope.results
$scope.reset();
}
$scope.reset = function() {
$scope.visibleOptions = [];
$scope.results = [];
$scope.showNextOption(-1);
}
$scope.reset();
}
ビュー
<div ng-app>
<h2>Options</h2>
<div ng-controller="OptionsCtrl">
<form ng-submit="showNextOption()">
<ul class="unstyled">
<li ng-repeat="(index, option) in visibleOptions">
<input type="text" ng-model="results[index]['input']" required>
<select ng-model="results[index]['select']" required>
<option value="">select</option>
<option ng-repeat="select in option.select" value="{{select}}">{{select}}</option>
</select>
<button
type="submit"
ng-show="visibleOptions.length == index+1 && visibleOptions.length < options.length">Next</button>
</li>
</ul>
</form>
<button
ng-click="save()"
ng-show="visibleOptions.length == options.length">Save</button>
<br><br>
{{
results
}}
</div>
</div>
example here