diff --git a/src/ng/directive/select.js b/src/ng/directive/select.js index 852fcef639aa..b8bf240b086c 100644 --- a/src/ng/directive/select.js +++ b/src/ng/directive/select.js @@ -338,6 +338,12 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) { // - optionGroupsCache[?][0] is the parent: either the SELECT or OPTGROUP element optionGroupsCache = [[{element: selectElement, label:''}]]; + if (track && match[2] && valueName !== match[1]) { + throw ngOptionsMinErr('trackSelect', + "Do not use 'track by' when your select ('{0}') is different from your value ('{1}')", + match[1], valueName); + } + if (nullOption) { // compile the element since there might be bindings in it $compile(nullOption)(scope); diff --git a/test/ng/directive/selectSpec.js b/test/ng/directive/selectSpec.js index e896dc05836d..c5c1ca0cf1c5 100644 --- a/test/ng/directive/selectSpec.js +++ b/test/ng/directive/selectSpec.js @@ -877,6 +877,15 @@ describe('select', function() { expect(element.val()).toEqual('4'); }); + it('should throw an error when trying to combine track by with a complex select expression', function() { + expect(function() { + createSelect({ + 'ng-model': 'selected', + 'ng-options': 'item.id as item.name for item in values track by item.id' + }); + }).toThrowMinErr('ngOptions','trackSelect', "Do not use 'track by' when your select ('item.id') is different from your value ('item')"); + }); + it('should bind to scope value through experession', function() { createSelect({