@@ -449,6 +449,12 @@ function $RootScopeProvider() {
449
449
* values are examined for changes on every call to `$digest`.
450
450
* - The `listener` is called whenever any expression in the `watchExpressions` array changes.
451
451
*
452
+ * `$watchGroup` is more performant than watching each expression individually, and should be
453
+ * used when the listener does not need to know which expression has changed.
454
+ * If the listener needs to know which expression has changed,
455
+ * {@link ng.$rootScope.Scope#$watch $watch()} or
456
+ * {@link ng.$rootScope.Scope#$watchCollection $watchCollection()} should be used.
457
+ *
452
458
* @param {Array.<string|Function(scope)> } watchExpressions Array of expressions that will be individually
453
459
* watched using {@link ng.$rootScope.Scope#$watch $watch()}
454
460
*
@@ -457,7 +463,34 @@ function $RootScopeProvider() {
457
463
* The `newValues` array contains the current values of the `watchExpressions`, with the indexes matching
458
464
* those of `watchExpression`
459
465
* and the `oldValues` array contains the previous values of the `watchExpressions`, with the indexes matching
460
- * those of `watchExpression`
466
+ * those of `watchExpression`.
467
+ *
468
+ * Note that `newValues` and `oldValues` reflect the differences in each **individual**
469
+ * expression, and not the difference of the values between each call of the listener.
470
+ * That means the difference between `newValues` and `oldValues` cannot be used to determine
471
+ * which expression has changed / remained stable:
472
+ *
473
+ * ```js
474
+ *
475
+ * $scope.$watchGroup(['v1', 'v2'], function(newValues, oldValues) {
476
+ * console.log(newValues, oldValues);
477
+ * });
478
+ *
479
+ * // newValues, oldValues initially
480
+ * // [undefined, undefined], [undefined, undefined]
481
+ *
482
+ * $scope.v1 = 'a';
483
+ * $scope.v2 = 'a';
484
+ *
485
+ * // ['a', 'a'], [undefined, undefined]
486
+ *
487
+ * $scope.v2 = 'b'
488
+ *
489
+ * // v1 hasn't changed since it became `'a'`, therefore its oldValue is still `undefined`
490
+ * // ['a', 'b'], [undefined, 'a']
491
+ *
492
+ * ```
493
+ *
461
494
* The `scope` refers to the current scope.
462
495
* @returns {function() } Returns a de-registration function for all listeners.
463
496
*/
0 commit comments