Skip to content

Instantly share code, notes, and snippets.

@chris-martin
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chris-martin/8830351 to your computer and use it in GitHub Desktop.
Save chris-martin/8830351 to your computer and use it in GitHub Desktop.
<div ng-app="app">
<div ng-controller="Ctrl1">
<select ng-model="foo" ng-options="o as o.name for o in options">
</select>
</div>
<div ng-controller="Ctrl2">
<select ng-model="foo" ng-options="o.id as o.name for o in options">
</select>
</div>
</div>
var app = angular.module('app', [ 'controllers' ]);
var controllers = angular.module('controllers', []);
controllers.controller('Ctrl1', [ '$scope', function ($scope) {
$scope.options = [
{ id: 'a', name: 'Apple' },
{ id: 'b', name: 'Banana' }
];
function getOption (id) {
return $scope.options.filter(function (option) {
return option.id === id;
})[0];
}
$scope.foo = getOption('b');
} ]);
controllers.controller('Ctrl2', [ '$scope', function ($scope) {
$scope.options = [
{ id: 'a', name: 'Apple' },
{ id: 'b', name: 'Banana' }
];
$scope.foo = 'b';
} ]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment