- SPLessons

How can I iterate over the keys, value in ng-repeat in angular

Home > > Tutorial
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

How can I iterate over the keys, value in ng-repeat in angular

How can I iterate over the keys, value in ng-repeat in angular

 

Description

Hi every one, Now we are going to see how can I iterate over the keys, value in ng-repeat in angular. Step 1: We have a JSON object with key and value format. Step 2: We know with help of ng-repeat we can iterate the values of json object. Step 3: In our JSON object Key- College code and Value - College Name. Step 4: It's very easy to get the values in key-value pair by simple passing the (key,value) argument in ng-repeat. Like : (college_code, college_name) in spCtr.listColleges     [javascript] var app = angular.module('splessonApp',[]); app.controller("splessonsController",['$scope',function($scope){ var listColleges = this; listColleges.listColleges = { 'NR':'Nursing', 'PH': 'Pharmacy', 'MD':'Medicine', 'AH': 'Allied Health', 'GB':'GSBS' }; }]); [/javascript]   [html] <html ng-app="splessonApp"> <head> <title> List of SPLessons Colleges </title> </head> <body ng-controller="splessonsController as spCtr"> <select ng-model="spCtr.listColleges" > <option value="" selected="selected" > Select College </option> <option ng-repeat="(college_code, college_name) in spCtr.listColleges" value="college_code" > {{college_name}} </option> </select> </body> </html> [/html]