You can create your own injector and embed it in the component portal you created. -
createInjector(dataToPass): PortalInjector { const injectorTokens = new WeakMap(); injectorTokens.set(CONTAINER_DATA, dataToPass); return new PortalInjector(this._injector, injectorTokens); }
CONTAINER_DATA is a custom injector (InjectorToken) created by -
export const CONTAINER_DATA = new InjectionToken<{}>('CONTAINER_DATA');
To consume the created injector, use -
let containerPortal = new ComponentPortal(ComponentToPort, null, this.createInjector({ data1, data2 })); overlay.attach(containerPortal);
the overlay is an instance of OverlayRef (which is the exit portal)
Inside the "ComponentToPort" you will need to enter the created injector -
@Inject(CONTAINER_DATA) public componentData: any
More about this here -
https://github.com/angular/material2/issues/8322
https://github.com/angular/material2/issues/8322
Awadhoot
source share