Skip to content

Instantly share code, notes, and snippets.

@jonahbron
Last active October 20, 2015 19:15
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 jonahbron/7a1f0c5bff949e3765b6 to your computer and use it in GitHub Desktop.
Save jonahbron/7a1f0c5bff949e3765b6 to your computer and use it in GitHub Desktop.
<md-input-container>
<label>Select Menu</label>
<md-select aria-label="Select menu" ng-model="vm.model">
<md-option ng-value="item" ng-repeat="item in vm.options track by item.id" ng-bind="item.name" select-track-by="id" select-model="vm.model"></md-option>
</md-select>
</md-input-container>
'use strict';
(function () {
angular
.module('myApp')
.directive('selectTrackBy', SelectTrackByDirective);
function SelectTrackByDirective() {
return {
restrict: 'A',
scope: {
selectModel: '=',
ngValue: '=',
selectTrackBy: '@'
},
link: function (scope) {
if (scope.selectModel && scope.ngValue[scope.selectTrackBy] === scope.selectModel[scope.selectTrackBy]) {
scope.selectModel = scope.ngValue;
}
}
};
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment