|
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
|
@@ -2506,9 +2539,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
|
2506 | 2539 | }
|
2507 | 2540 | }
|
2508 | 2541 | if (isFunction(controllerInstance.$doCheck)) {
|
2509 |
| - controllerInstance.$doCheck(); |
2510 |
| - } |
2511 |
| - if (isFunction(controllerInstance.$doCheck)) { |
| 2542 | + controllerScope.$watch(function() { controllerInstance.$doCheck(); }); |
2512 | 2543 | controllerInstance.$doCheck();
|
2513 | 2544 | }
|
2514 | 2545 | if (isFunction(controllerInstance.$onDestroy)) {
|
@@ -3275,11 +3306,6 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
|
3275 | 3306 | }
|
3276 | 3307 | });
|
3277 | 3308 |
|
3278 |
| - if (isFunction(destination.$doCheck)) { |
3279 |
| - var doCheckWatch = scope.$watch(triggerDoCheckHook); |
3280 |
| - removeWatchCollection.push(doCheckWatch); |
3281 |
| - } |
3282 |
| - |
3283 | 3309 | function recordChanges(key, currentValue, previousValue) {
|
3284 | 3310 | if (isFunction(destination.$onChanges) && currentValue !== previousValue) {
|
3285 | 3311 | // If we have not already scheduled the top level onChangesQueue handler then do so now
|
@@ -3307,10 +3333,6 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
|
3307 | 3333 | changes = undefined;
|
3308 | 3334 | }
|
3309 | 3335 |
|
3310 |
| - function triggerDoCheckHook() { |
3311 |
| - destination.$doCheck(); |
3312 |
| - } |
3313 |
| - |
3314 | 3336 | return {
|
3315 | 3337 | initialChanges: initialChanges,
|
3316 | 3338 | removeWatches: removeWatchCollection.length && function removeWatches() {
|
|
0 commit comments