Skip to content

fix(slide-toggle): run timeout outside the NgZone #10655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/lib/slide-toggle/slide-toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import {
OnDestroy,
Output,
ViewChild,
ViewEncapsulation
ViewEncapsulation,
NgZone,
} from '@angular/core';
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';
import {
Expand Down Expand Up @@ -144,7 +145,8 @@ export class MatSlideToggle extends _MatSlideToggleMixinBase implements OnDestro
private _platform: Platform,
private _focusMonitor: FocusMonitor,
private _changeDetectorRef: ChangeDetectorRef,
@Attribute('tabindex') tabIndex: string) {
@Attribute('tabindex') tabIndex: string,
private _ngZone: NgZone) {

super(elementRef);
this.tabIndex = parseInt(tabIndex) || 0;
Expand Down Expand Up @@ -274,9 +276,11 @@ export class MatSlideToggle extends _MatSlideToggleMixinBase implements OnDestro
this._emitChangeEvent();
}

// The drag should be stopped outside of the current event handler, because otherwise the
// click event will be fired before and will revert the drag change.
setTimeout(() => this._slideRenderer.stopThumbDrag());
// The drag should be stopped outside of the current event handler, otherwise the
// click event will be fired before it and will revert the drag change.
this._ngZone.runOutsideAngular(() => {
setTimeout(() => this._slideRenderer.stopThumbDrag());
});
}
}

Expand Down