From 63e785902fbc6d5edbc1a4ed135f65d1cdf00acd Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 11 Sep 2015 14:53:49 -0700 Subject: [PATCH] feat(change_detection): allow triggering CD form ChangeDetectorRef Closes #4144 --- .../change_detection/change_detector_ref.ts | 2 ++ .../change_detector_ref_spec.ts | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 modules/angular2/test/core/change_detection/change_detector_ref_spec.ts diff --git a/modules/angular2/src/core/change_detection/change_detector_ref.ts b/modules/angular2/src/core/change_detection/change_detector_ref.ts index 8e5bf2f17a..40bfbaf710 100644 --- a/modules/angular2/src/core/change_detection/change_detector_ref.ts +++ b/modules/angular2/src/core/change_detection/change_detector_ref.ts @@ -25,6 +25,8 @@ export class ChangeDetectorRef { */ detach(): void { this._cd.mode = ChangeDetectionStrategy.Detached; } + detectChanges(): void { this._cd.detectChanges(); } + /** * Reattach the change detector to the change detector tree. * diff --git a/modules/angular2/test/core/change_detection/change_detector_ref_spec.ts b/modules/angular2/test/core/change_detection/change_detector_ref_spec.ts new file mode 100644 index 0000000000..dbf031b123 --- /dev/null +++ b/modules/angular2/test/core/change_detection/change_detector_ref_spec.ts @@ -0,0 +1,28 @@ +import { + ddescribe, + describe, + it, + iit, + xit, + expect, + beforeEach, + afterEach, + tick, + fakeAsync +} from 'angular2/test_lib'; + +import {ChangeDetectorRef} from 'angular2/src/core/change_detection/change_detector_ref'; +import {SpyChangeDetector} from '../spies'; + + +export function main() { + describe('ChangeDetectorRef', () => { + it('should delegate detectChanges()', () => { + var changeDetector = new SpyChangeDetector(); + changeDetector.spy('detectChanges'); + var changeDetectorRef = new ChangeDetectorRef(changeDetector); + changeDetectorRef.detectChanges(); + expect(changeDetector.spy('detectChanges')).toHaveBeenCalled(); + }); + }); +}