docs(forms): add inline docs why `ngModel` runs a 2nd change detection run (#12821)

Related to #11895
This commit is contained in:
Tobias Bosch 2016-11-11 15:24:11 -08:00 committed by Victor Berchet
parent 785b7b640e
commit 69dfcf7385
1 changed files with 17 additions and 0 deletions

View File

@ -27,6 +27,23 @@ export const formControlBinding: any = {
useExisting: forwardRef(() => NgModel)
};
/**
* `ngModel` forces an additional change detection run when its inputs change:
* E.g.:
* ```
* <div>{{myModel.valid}}</div>
* <input [(ngModel)]="myValue" #myModel="ngModel">
* ```
* I.e. `ngModel` can export itself on the element and then be used in the template.
* Normally, this would result in expressions before the `input` that use the exported directive
* to have and old value as they have been
* dirty checked before. As this is a very common case for `ngModel`, we added this second change
* detection run.
*
* Notes:
* - this is just one extra run no matter how many `ngModel` have been changed.
* - this is a general problem when using `exportAs` for directives!
*/
const resolvedPromise = Promise.resolve(null);
/**