Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit d576b64

Browse files
committed
docs(select): fix formatting of and placement of selectAs/trackAs explanation
1 parent df1a00b commit d576b64

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

src/ng/directive/select.js

+14-17
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ var ngOptionsMinErr = minErr('ngOptions');
4141
* or property name (for object data sources) of the value within the collection.
4242
* </div>
4343
*
44+
* **Note:** Using `select as` together with `trackexpr` is not possible (and will throw).
45+
* Reasoning:
46+
* - Example: &lt;select ng-options="item.subItem as item.label for item in values track by item.id" ng-model="selected"&gt;
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+
*
4458
* @param {string} ngModel Assignable angular expression to data-bind to.
4559
* @param {string=} name Property name of the form under which the control is published.
4660
* @param {string=} required The control is considered valid only if value is entered.
@@ -77,23 +91,6 @@ var ngOptionsMinErr = minErr('ngOptions');
7791
* used to identify the objects in the array. The `trackexpr` will most likely refer to the
7892
* `value` variable (e.g. `value.propertyName`). With this the selection is preserved
7993
* 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>
9794
*
9895
* @example
9996
<example module="selectExample">

0 commit comments

Comments
 (0)