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

docs(ngModel): add section explaining ngModel watching by reference #13518

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
15 changes: 15 additions & 0 deletions src/ng/directive/ngModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,21 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
* - {@link ng.directive:select select}
* - {@link ng.directive:textarea textarea}
*
* # Complex Models (objects or collections)
*
* By default, `ngModel` watches the model by reference, not value. This is important to know when
* binding elements to models that are objects or collections. If properties of the object or collection
* change, the model won't be re-rendered unless the identity of the object is also changed. If the model
* is assigned to an entirely new object, its identity will be changed and a re-rendering will trigger.
*
* The rootScope method `$watchCollection` can be used to watch for changes, but it does a shallow comparison,
* meaning that changing properties deeper than the first level of the object (or of the item in the collection
* if it's an array) will not trigger a re-rendering of the model.
*
* Some directives have options that will cause them to use `$watchCollection` - for example, `ngOptions`
* will do so when a `track by` clause is included in the comprehension expression or if the select is given
* the `multiple` attribute.
*
* # CSS classes
* The following CSS classes are added and removed on the associated input/select/textarea element
* depending on the validity of the model.
Expand Down