Skip to content

Instantly share code, notes, and snippets.

@sondreb
Last active August 29, 2015 14:07
Show Gist options
  • Save sondreb/159a9292f4b681106842 to your computer and use it in GitHub Desktop.
Save sondreb/159a9292f4b681106842 to your computer and use it in GitHub Desktop.
Two examples of binding JSON-annotated object with select in HTML using AngularJS
$scope.sort = 'relevance';
$scope.sorting = {
'relevance': 'Relevant',
'date-posted-desc': 'Recent',
'interestingness-desc': 'Interesting'
};
$scope.sorting2 = [
{'id': 'relevance', 'text': 'Relevant'},
{ 'id': 'date-posted-desc', 'text': 'Recent'},
{ 'id': 'interestingness-desc', 'text': 'Interesting'}
];
<!-- No options is rendered if ng-models is missing. -->
<select ng-model="sort" ng-options="k as v for (k,v) in sorting"></select>
<select ng-model="sort" ng-options="sort.id as sort.text for sort in sorting2"></select>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment