@@ -41,6 +41,20 @@ var ngOptionsMinErr = minErr('ngOptions');
41
41
* or property name (for object data sources) of the value within the collection.
42
42
* </div>
43
43
*
44
+ * **Note:** Using `select as` together with `trackexpr` is not possible (and will throw).
45
+ * Reasoning:
46
+ * - Example: <select ng-options="item.subItem as item.label for item in values track by item.id" ng-model="selected">
47
+ * values: [{id: 1, label: 'aLabel', subItem: {name: 'aSubItem'}}, {id: 2, label: 'bLabel', subItem: {name: 'bSubItemß'}}],
48
+ * $scope.selected = {name: 'aSubItem'};
49
+ * - track by is always applied to `value`, with purpose to preserve the selection,
50
+ * (to `item` in this case)
51
+ * - to calculate whether an item is selected we do the following:
52
+ * 1. apply `track by` to the values in the array, e.g.
53
+ * In the example: [1,2]
54
+ * 2. apply `track by` to the already selected value in `ngModel`:
55
+ * In the example: this is not possible, as `track by` refers to `item.id`, but the selected
56
+ * value from `ngModel` is `{name: aSubItem}`.
57
+ *
44
58
* @param {string } ngModel Assignable angular expression to data-bind to.
45
59
* @param {string= } name Property name of the form under which the control is published.
46
60
* @param {string= } required The control is considered valid only if value is entered.
@@ -77,23 +91,6 @@ var ngOptionsMinErr = minErr('ngOptions');
77
91
* used to identify the objects in the array. The `trackexpr` will most likely refer to the
78
92
* `value` variable (e.g. `value.propertyName`). With this the selection is preserved
79
93
* even when the options are recreated (e.g. reloaded from the server).
80
-
81
- * <div class="alert alert-info">
82
- * **Note:** Using `select as` together with `trackexpr` is not possible (and will throw).
83
- * Reasoning:
84
- * - Example: <select ng-options="item.subItem as item.label for item in values track by item.id" ng-model="selected">
85
- * values: [{id: 1, label: 'aLabel', subItem: {name: 'aSubItem'}}, {id: 2, label: 'bLabel', subItem: {name: 'bSubItemß'}}],
86
- * $scope.selected = {name: 'aSubItem'};
87
- * - track by is always applied to `value`, with purpose to preserve the selection,
88
- * (to `item` in this case)
89
- * - to calculate whether an item is selected we do the following:
90
- * 1. apply `track by` to the values in the array, e.g.
91
- * In the example: [1,2]
92
- * 2. apply `track by` to the already selected value in `ngModel`:
93
- * In the example: this is not possible, as `track by` refers to `item.id`, but the selected
94
- * value from `ngModel` is `{name: aSubItem}`.
95
- *
96
- * </div>
97
94
*
98
95
* @example
99
96
<example module="selectExample">
0 commit comments