Skip to content
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

fix(module: Toast): fix tasks can reenter the Angular zone via run #93

Merged
merged 2 commits into from
Nov 1, 2018
Merged
Show file tree
Hide file tree
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
12 changes: 8 additions & 4 deletions components/toast/toast.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, ViewEncapsulation, Input, TemplateRef, HostBinding } from '@angular/core';
import { Component, ViewEncapsulation, Input, TemplateRef, HostBinding, NgZone } from '@angular/core';

@Component({
selector: 'Toast',
Expand Down Expand Up @@ -26,14 +26,18 @@ export class ToastComponent {
} else {
this.isContentString = true;
}
this._content = value;
this._zone.run(() => {
this._content = value;
});
}
@Input()
get iconType(): string {
return this._iconType;
}
set iconType(value: string) {
this._iconType = value;
this._zone.run(() => {
this._iconType = value;
});
}

@HostBinding('class.am-toast')
Expand All @@ -47,5 +51,5 @@ export class ToastComponent {
return !this.mask;
}

constructor() {}
constructor(private _zone: NgZone) {}
}
9 changes: 7 additions & 2 deletions components/toast/toast.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ComponentFactory,
ApplicationRef,
Compiler,
NgZone,
ComponentFactoryResolver,
} from '@angular/core';
import { ToastComponent } from './toast.component';
Expand All @@ -18,11 +19,13 @@ export interface ConfigInterface {
@Injectable()
export class Toast {
static timeout = null;
static _zone: NgZone = null;
static compRef: ComponentRef<any> = null;
static _toastCompFactory: ComponentFactory<ToastComponent> = null;
static _appRef: ApplicationRef = null;

constructor(private _appRef: ApplicationRef, private _compiler: Compiler, private _cfr: ComponentFactoryResolver) {
constructor(private _appRef: ApplicationRef, private _compiler: Compiler, private _cfr: ComponentFactoryResolver, private _zone: NgZone) {
Toast._zone = this._zone;
Toast._appRef = this._appRef;
Toast._toastCompFactory = this._cfr.resolveComponentFactory(ToastComponent);
}
Expand Down Expand Up @@ -141,7 +144,9 @@ export class Toast {
clearTimeout(Toast.timeout);
}
if (Toast.compRef) {
Toast.compRef.destroy();
Toast._zone.run(() => {
Toast.compRef.destroy();
});
Toast.compRef = null;
}
}
Expand Down