|
316 | 316 | * they are waiting for their template to load asynchronously and their own compilation and linking has been
|
317 | 317 | * suspended until that occurs.
|
318 | 318 | *
|
| 319 | + * ** $doCheck example ** |
| 320 | + * |
| 321 | + * This example show how you might use `$doCheck` to customise the equality check of component inputs. |
| 322 | + * |
| 323 | + * <example name="doCheckExample" module="do-check-module"> |
| 324 | + * <file name="index.html"> |
| 325 | + * <div ng-init="items = []"> |
| 326 | + * <button ng-click="items.push(items.length)">Add Item</button> |
| 327 | + * <button ng-click="items = []">Reset Items</button> |
| 328 | + * <pre>{{ items }}</pre> |
| 329 | + * <test items="items"></test> |
| 330 | + * </div> |
| 331 | + * </file> |
| 332 | + * <file name="app.js"> |
| 333 | + * angular.module('do-check-module', []) |
| 334 | + * .component('test', { |
| 335 | + * bindings: { items: '<' }, |
| 336 | + * template: |
| 337 | + * '<pre>{{ $ctrl.log | json }}</pre>', |
| 338 | + * controller: function() { |
| 339 | + * this.log = []; |
| 340 | + * |
| 341 | + * this.$doCheck = function() { |
| 342 | + * if (this.items_ref !== this.items) { this.log.push('doCheck: items changed'); } |
| 343 | + * if (!angular.equals(this.items_clone, this.items)) { this.log.push('doCheck: items mutated'); } |
| 344 | + * |
| 345 | + * this.items_clone = angular.copy(this.items); |
| 346 | + * this.items_ref = this.items; |
| 347 | + * }; |
| 348 | + * } |
| 349 | + * }); |
| 350 | + * </file> |
| 351 | + * </example> |
319 | 352 | *
|
320 | 353 | * #### `require`
|
321 | 354 | * Require another directive and inject its controller as the fourth argument to the linking function. The
|
@@ -2519,9 +2552,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
|
2519 | 2552 | }
|
2520 | 2553 | }
|
2521 | 2554 | if (isFunction(controllerInstance.$doCheck)) {
|
2522 |
| - controllerInstance.$doCheck(); |
2523 |
| - } |
2524 |
| - if (isFunction(controllerInstance.$doCheck)) { |
| 2555 | + controllerScope.$watch(function() { controllerInstance.$doCheck(); }); |
2525 | 2556 | controllerInstance.$doCheck();
|
2526 | 2557 | }
|
2527 | 2558 | if (isFunction(controllerInstance.$onDestroy)) {
|
@@ -3282,11 +3313,6 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
|
3282 | 3313 | }
|
3283 | 3314 | });
|
3284 | 3315 |
|
3285 |
| - if (isFunction(destination.$doCheck)) { |
3286 |
| - var doCheckWatch = scope.$watch(triggerDoCheckHook); |
3287 |
| - removeWatchCollection.push(doCheckWatch); |
3288 |
| - } |
3289 |
| - |
3290 | 3316 | function recordChanges(key, currentValue, previousValue) {
|
3291 | 3317 | if (isFunction(destination.$onChanges) && currentValue !== previousValue) {
|
3292 | 3318 | // If we have not already scheduled the top level onChangesQueue handler then do so now
|
@@ -3314,10 +3340,6 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
|
3314 | 3340 | changes = undefined;
|
3315 | 3341 | }
|
3316 | 3342 |
|
3317 |
| - function triggerDoCheckHook() { |
3318 |
| - destination.$doCheck(); |
3319 |
| - } |
3320 |
| - |
3321 | 3343 | return {
|
3322 | 3344 | initialChanges: initialChanges,
|
3323 | 3345 | removeWatches: removeWatchCollection.length && function removeWatches() {
|
|
0 commit comments