diff --git a/src/ng/directive/select.js b/src/ng/directive/select.js index fe17c903c522..21c7baa6bc7f 100644 --- a/src/ng/directive/select.js +++ b/src/ng/directive/select.js @@ -41,6 +41,20 @@ var ngOptionsMinErr = minErr('ngOptions'); * or property name (for object data sources) of the value within the collection. * * + * **Note:** Using `select as` together with `trackexpr` is not possible (and will throw). + * Reasoning: + * - Example: <select ng-options="item.subItem as item.label for item in values track by item.id" ng-model="selected"> + * values: [{id: 1, label: 'aLabel', subItem: {name: 'aSubItem'}}, {id: 2, label: 'bLabel', subItem: {name: 'bSubItemß'}}], + * $scope.selected = {name: 'aSubItem'}; + * - track by is always applied to `value`, with purpose to preserve the selection, + * (to `item` in this case) + * - to calculate whether an item is selected we do the following: + * 1. apply `track by` to the values in the array, e.g. + * In the example: [1,2] + * 2. apply `track by` to the already selected value in `ngModel`: + * In the example: this is not possible, as `track by` refers to `item.id`, but the selected + * value from `ngModel` is `{name: aSubItem}`. + * * @param {string} ngModel Assignable angular expression to data-bind to. * @param {string=} name Property name of the form under which the control is published. * @param {string=} required The control is considered valid only if value is entered. @@ -77,23 +91,6 @@ var ngOptionsMinErr = minErr('ngOptions'); * used to identify the objects in the array. The `trackexpr` will most likely refer to the * `value` variable (e.g. `value.propertyName`). With this the selection is preserved * even when the options are recreated (e.g. reloaded from the server). - - *
- * **Note:** Using `select as` together with `trackexpr` is not possible (and will throw). - * Reasoning: - * - Example: