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

docs(select): fix formatting of and placement of selectAs/trackAs explanation #9503

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions src/ng/directive/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ var ngOptionsMinErr = minErr('ngOptions');
* or property name (for object data sources) of the value within the collection.
* </div>
*
* **Note:** Using `select as` together with `trackexpr` is not possible (and will throw).
* Reasoning:
* - Example: &lt;select ng-options="item.subItem as item.label for item in values track by item.id" ng-model="selected"&gt;
* 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.
Expand Down Expand Up @@ -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).

* <div class="alert alert-info">
* **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}`.
*
* </div>
*
* @example
<example module="selectExample">
Expand Down