Skip to content

Commit

Permalink
fix(module: Toast): fix tasks can reenter the Angular zone via run (N…
Browse files Browse the repository at this point in the history
…G-ZORRO#93)

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

fix(module: Toast): fix tasks can be kicked off via runOutsideAngular and if needed, these tasks can reenter the Angular zone via run

* fix(module: Toast): fix zone init value of null
  • Loading branch information
Guoyuanqiang committed Nov 1, 2018
1 parent bb59fe7 commit 49d52be
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
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

0 comments on commit 49d52be

Please sign in to comment.