forked from angular/angular.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrkslct.ngdoc
28 lines (24 loc) · 1.37 KB
/
trkslct.ngdoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
@ngdoc error
@name ngOptions:trkslct
@fullName Comprehension expression cannot contain both selectAs and trackBy expressions.
@description
This error occurs when 'ngOptions' is passed a comprehension expression that contains both a
`select as` expression and a `track by` expression. These two expressions are fundamentally
incompatible.
* Example of bad expression: `<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'};`
* trackBy is always applied to `value`, with purpose to preserve the selection,
(to `item` in this case)
* To calculate whether an item is selected, `ngOptions` does the following:
1. apply `trackBy` to the values in the array, e.g.
In the example: [1,2]
2. apply `trackBy` to the already selected value in `ngModel`:
In the example: this is not possible, as `trackBy` refers to `item.id`, but the selected
value from `ngModel` is `{name: aSubItem}`.
Here's an example of correct syntax:
```
//track by with array
<select ng-model="selected" ng-options="item.label for item in values track by item.id">
```
For more information on valid expression syntax, see 'ngOptions' in {@link ng.directive:select select} directive docs.