testFiddle

Testing ng-repeat with ng-options

by Danish Farman

HTML

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js"></script>
<div ng-controller="testCtrl">
    <table border="1" style="width:300px">
        <tr>
        <th>id</th>
        <th>name</th>
        <th>age</th>
        <th>select</th>
        </tr>
        <tr ng-repeat="person in persons">                        
            <td>{{ person.id }}</td>
            <td>{{ person.name }}</td>
            <td>{{ person.age }}</td>               
            <td>
            <select ng-model="person.chosenNumber" ng-options="suggestion.number as suggestion.destination for suggestion in person.suggestedPhones"></select>
            <button ng-click="showSelected(person)">Ok</button>
            </td>
        </tr>        
    </table>
</div>

JavaScript

var testModule = angular.module('myApp', []);
    
function testCtrl($scope) {                      
    
	$scope.persons = [
	    {'id': 1, 'name': 'omer', 'age': 35,  'suggestedPhones': [{'destination': 'home', 'number': '0544317259'}] },
	    {'id': 2, 'name': 'noam', 'age': 32, 'suggestedPhones': [{'destination': 'home', 'number': '036024607'}] },
	    {'id': 3, 'name': 'dafna', 'age': 28, 'suggestedPhones': [{'destination': 'home', 'number': '0522318779'}] }
	]
	
	$scope.showSelected = function (person) {
	    console.log(person);	    
	}
}