From 69dfcf73853d63f4fbaf4c8f44a7dbff689bbc81 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Fri, 11 Nov 2016 15:24:11 -0800 Subject: [PATCH] docs(forms): add inline docs why `ngModel` runs a 2nd change detection run (#12821) Related to #11895 --- .../@angular/forms/src/directives/ng_model.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/modules/@angular/forms/src/directives/ng_model.ts b/modules/@angular/forms/src/directives/ng_model.ts index 91c1229534..31e3b96245 100644 --- a/modules/@angular/forms/src/directives/ng_model.ts +++ b/modules/@angular/forms/src/directives/ng_model.ts @@ -27,6 +27,23 @@ export const formControlBinding: any = { useExisting: forwardRef(() => NgModel) }; +/** + * `ngModel` forces an additional change detection run when its inputs change: + * E.g.: + * ``` + *
{{myModel.valid}}
+ * + * ``` + * 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); /**