Örnek json verimizi hazırlayalım:
$scope.countries = [{ name: "UK", cities: [{ name: "UK 1" }, { name: "UK 2" }, { name: "UK 3" }] }, { name: "US", cities: [{ name: "US 1" }, { name: "US 2" }, { name: "US 3" }] }, { name: "India", cities: [{ name: "India 1" }, { name: "India 2" }, { name: "India 3" }] }];
Şimdi HTML kodumuzu yazalım:
<ul> <li ng-repeat="country in countries"> {{country.name}} <ul> <li ng-repeat="city in country.cities"> {{city.name}} </li> </ul> </li> </ul>
Kodumuzun tamamı aşağıdaki gibi olacak:
<html> <head> </head> <body> <div ng-app="myModule" ng-controller="myController"> <ul> <li ng-repeat="country in countries"> {{country.name}} <ul> <li ng-repeat="city in country.cities"> {{city.name}} </li> </ul> </li> </ul> </div> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script> <script> var myApp = angular.module("myModule", []).controller("myController", function($scope) { $scope.countries = [{ name: "UK", cities: [{ name: "UK 1" }, { name: "UK 2" }, { name: "UK 3" }] }, { name: "US", cities: [{ name: "US 1" }, { name: "US 2" }, { name: "US 3" }] }, { name: "India", cities: [{ name: "India 1" }, { name: "India 2" }, { name: "India 3" }] }]; }) </script> </body> </html>
Sonuç aşağıdaki gibi olacak: