Click here to Skip to main content
14,695,503 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new in AngularJS. In my code I have two nested ng-repeat attribute and I want to use first ng-repeat variable value to create the next ng-repeat variable. Here is my Code that not as I need.


<div ng-repeat="item in artType">    
	<select ng-model="ddlArtType">
		<option value="" disabled selected> </option>
		<option ng-repeat="selectedArtType in artCultureDependencyMap.{{item}} track by $index">
			{{selectedArtType}}
		</option>
	</select>    
</div>



Here "artType" is an array, Example value
artType=['Film', 'Music',...]
And "artCultureDependencyMap" is an object. Example value
artCultureDependencyMap['Film']=['Action','Adventure',....]
artCultureDependencyMap['Music']=['xxx','yyy',....]

What should I do here. Your any help will greatly appreciated.
Sazzad
Posted
Updated 6-Dec-15 1:40am
v2

1 solution

I assumed that you are struggling with nested ng-repeat. Hope the following code will help you.

<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="myCtrl">

	<div ng-repeat="item in artType">    
	<select ng-model="ddlArtType">
		<option value="" disabled selected> </option>
		<option ng-repeat="selectedArtType in artCultureDependencyMap[item] track by $index">
			{{selectedArtType}}
		</option>
	</select>    
</div>

</div>

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
	
	$scope.artType=['Film', 'Music', 'Sports'];
	
	$scope.artCultureDependencyMap = {};
	$scope.artCultureDependencyMap['Film'] = ['Film1', 'Film2', 'Film3'];
	$scope.artCultureDependencyMap['Music'] = ['Music1', 'Music2', 'Music3'];
	$scope.artCultureDependencyMap['Sports'] = ['Sports1', 'Sports2', 'Sports3'];
});
</script>

</body>
</html>
   
Comments
sazzad37 6-Dec-15 12:33pm
   
Thank you very much. This is what I searching for.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900