Skip to content

Instantly share code, notes, and snippets.

@rlfrahm
Last active August 29, 2015 14:11
Show Gist options
  • Save rlfrahm/58c673c4786c88c233dc to your computer and use it in GitHub Desktop.
Save rlfrahm/58c673c4786c88c233dc to your computer and use it in GitHub Desktop.
AngularJs ngOptions for array and object types

AngularJS : ngOptions for Arrays and Objects

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
<script>
angular.module('app', [])
.controller('AppCtrl', ['$scope',function($scope) {
$scope.array = [{label:'Label 1'},{label:'Label 2'},{label:'Label 3'}];
$scope.object = {item1:{label:'Label 1'},item2:{label:'Label 2'},item3:{label:'Label 3'}};
}]);
</script>
<body ng-app="app" ng-controller="AppCtrl">
<select class="form-control" ng-options="item.label for item in array" ng-model="selectedArrayItem"></select>
<select class="form-control" ng-options="item.label for (key,item) in object" ng-model="selectedObjectItem"></select>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment