@@ -33,20 +33,28 @@ var ngOptionsMinErr = minErr('ngOptions');
33
33
*
34
34
* ## Complex Models (objects or collections)
35
35
*
36
- * **Note:** By default, `ngModel` watches the model by reference, not value. This is important when
37
- * binding any input directive to a model that is an object or a collection.
36
+ * By default, `ngModel` watches the model by reference, not value. This is important to know when
37
+ * binding the select to a model that is an object or a collection.
38
38
*
39
- * Since this is a common situation for `ngOptions` the directive additionally watches the model using
40
- * `$watchCollection` when the select has the `multiple` attribute or when there is a `track by` clause in
41
- * the options expression. This allows ngOptions to trigger a re-rendering of the options even if the actual
42
- * object/collection has not changed identity but only a property on the object or an item in the collection
43
- * changes.
39
+ * One issue occurs if you want to preselect an option. For example, if you set
40
+ * the model to an object that is equal to an object in your collection, `ngOptions` won't be able to set the selection,
41
+ * because the objects are not identical. So by default, you should always reference the item in your collection
42
+ * for preselections, e.g.: `$scope.selected = $scope.collection[3]`.
43
+ *
44
+ * Another solution is to use a `track by` clause, because then `ngOptions` will track the identity
45
+ * of the item not by reference, but by the result of the `track by` expression. For example, if your
46
+ * collection items have an id property, you would `track by item.id`.
47
+ *
48
+ * A different issue with objects or collections is that ngModel won't detect if an object property or
49
+ * a collection item changes. For that reason, `ngOptions` additionally watches the model using
50
+ * `$watchCollection`, when the expression contains a `track by` clause or the the select has the `multiple` attribute.
51
+ * This allows ngOptions to trigger a re-rendering of the options even if the actual object/collection
52
+ * has not changed identity, but only a property on the object or an item in the collection changes.
44
53
*
45
54
* Note that `$watchCollection` does a shallow comparison of the properties of the object (or the items in the collection
46
55
* if the model is an array). This means that changing a property deeper than the first level inside the
47
56
* object/collection will not trigger a re-rendering.
48
57
*
49
- *
50
58
* ## `select` **`as`**
51
59
*
52
60
* Using `select` **`as`** will bind the result of the `select` expression to the model, but
0 commit comments