Skip to content
Snippets Groups Projects
Commit e1fca130 authored by Scott Cooper's avatar Scott Cooper
Browse files

allow for component inheritance without AoT

parent cef5027a
Branches
Tags 4.4.0
No related merge requests found
......@@ -5,11 +5,11 @@ import {
transition,
animate,
style,
ApplicationRef,
} from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
import { Toast, ToastData, ToastrService, ToastRef } from 'ngx-toastr';
import { Toast } from 'ngx-toastr';
/* tslint:disable */
@Component({
selector: '[pink-toast-component]',
styles: [`
......@@ -53,6 +53,18 @@ import { Toast } from 'ngx-toastr';
export class PinkToast extends Toast {
// used for demo purposes
undoString = 'undo';
// constructor is only necessary when not using AoT
constructor(
protected toastrService: ToastrService,
public data: ToastData,
protected toastRef: ToastRef<any>,
protected appRef: ApplicationRef,
protected sanitizer: DomSanitizer
) {
super(toastrService, data, toastRef, appRef, sanitizer);
}
action(event: Event) {
event.stopPropagation();
this.undoString = 'undid';
......@@ -61,4 +73,3 @@ export class PinkToast extends Toast {
return false;
}
}
/* tslint:enable */
import { ComponentFactoryResolver, Injectable, ApplicationRef, Injector, NgZone } from '@angular/core';
import { ComponentFactoryResolver, Injectable, ApplicationRef, NgZone } from '@angular/core';
import { DomPortalHost } from '../portal/dom-portal-host';
import { OverlayRef } from './overlay-ref';
......@@ -20,7 +20,6 @@ import { ToastContainerDirective } from '../toast-directive';
constructor(private _overlayContainer: OverlayContainer,
private _componentFactoryResolver: ComponentFactoryResolver,
private _appRef: ApplicationRef,
private _injector: Injector,
private _ngZone: NgZone) {}
/**
* Creates an overlay.
......@@ -61,7 +60,7 @@ import { ToastContainerDirective } from '../toast-directive';
* @returns A portal host for the given DOM element.
*/
private _createPortalHost(pane: HTMLElement): DomPortalHost {
return new DomPortalHost(pane, this._componentFactoryResolver, this._appRef, this._injector);
return new DomPortalHost(pane, this._componentFactoryResolver, this._appRef);
}
/**
......
{
"name": "ngx-toastr",
"version": "4.3.0",
"version": "4.4.0",
"description": "Toastr for Angular",
"main": "toastr.umd.js",
"module": "toastr.js",
......
......@@ -3,7 +3,6 @@ import {
ComponentRef,
EmbeddedViewRef,
ApplicationRef,
Injector,
} from '@angular/core';
import {BasePortalHost, ComponentPortal} from './portal';
......@@ -18,8 +17,7 @@ export class DomPortalHost extends BasePortalHost {
constructor(
private _hostDomElement: Element,
private _componentFactoryResolver: ComponentFactoryResolver,
private _appRef: ApplicationRef,
private _defaultInjector: Injector) {
private _appRef: ApplicationRef) {
super();
}
......@@ -36,7 +34,7 @@ export class DomPortalHost extends BasePortalHost {
// When the ViewContainerRef is missing, we use the factory to create the component directly
// and then manually attach the ChangeDetector for that component to the application (which
// happens automatically when using a ViewContainer).
componentRef = componentFactory.create(portal.injector || this._defaultInjector);
componentRef = componentFactory.create(portal.injector);
// When creating a component outside of a ViewContainer, we need to manually register
// its ChangeDetector with the application. This API is unfortunately not yet published
......
......@@ -74,11 +74,11 @@ export class Toast implements OnDestroy {
onAction: Subject<any>;
constructor(
private toastrService: ToastrService,
protected toastrService: ToastrService,
public data: ToastData,
private toastRef: ToastRef<any>,
private appRef: ApplicationRef,
sanitizer: DomSanitizer
protected toastRef: ToastRef<any>,
protected appRef: ApplicationRef,
protected sanitizer: DomSanitizer
) {
this.options = data.optionsOverride;
this.toastId = data.toastId;
......
......@@ -5,5 +5,6 @@ export { ToastContainerModule, ToastContainerDirective } from './toast-directive
export { OverlayRef } from './overlay/overlay-ref';
export { Toast } from './toast-component';
export { ToastrService, ActiveToast } from './toastr-service';
export { ToastrConfig, ToastConfig } from './toastr-config';
export { ToastrConfig, ToastConfig, ToastData } from './toastr-config';
export { ToastrModule } from './toastr-module';
export { ToastRef } from './toast-injector';
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment