fix(change_detection): ChangeDetectorRef reattach should restore original mode

After using ChangeDetectorRef detach, it should keep the ChangeDetector mode so that it is restored after calling reattach.

closes #7078
closes #7080
This commit is contained in:
Alfonso Presa
2016-02-15 00:02:11 +01:00
committed by Tobias Bosch
parent 791153c93c
commit 773c34900f
2 changed files with 52 additions and 3 deletions

View File

@ -80,7 +80,13 @@ export abstract class EmbeddedViewRef<C> extends ViewRef {
}
export class ViewRef_<C> implements EmbeddedViewRef<C>, ChangeDetectorRef {
constructor(private _view: AppView<C>) { this._view = _view; }
/** @internal */
_originalMode: ChangeDetectionStrategy;
constructor(private _view: AppView<C>) {
this._view = _view;
this._originalMode = this._view.cdMode;
}
get internalView(): AppView<C> { return this._view; }
@ -95,7 +101,7 @@ export class ViewRef_<C> implements EmbeddedViewRef<C>, ChangeDetectorRef {
detectChanges(): void { this._view.detectChanges(false); }
checkNoChanges(): void { this._view.detectChanges(true); }
reattach(): void {
this._view.cdMode = ChangeDetectionStrategy.CheckAlways;
this._view.cdMode = this._originalMode;
this.markForCheck();
}