I have defined a search service as follows.
import { Subject } from "rxjs/Subject";
export class SearchTextEmitter extends Subject<string>{
constructor() {
super();
}
emit(value) { super.next(value); }
}
export class SearchTextService {
searchText = new SearchTextEmitter();
}
I am publishing with emit and subscribing in a child component that is a lazy loaded child of the parent.
If the child component is declared, and included as a module, the search text is correctly propogated downwards.
export const routes: Routes = [
{
path: "",
redirectTo: "dashboard",
pathMatch: "full",
},
{
path: "",
component: FullLayoutComponent,
data: {
title: "Home"
},
children: [
{
path: "dashboard",
component: ClearingDashboardComponent
...
}
When the child module is lazy loaded as follows...
// instead of
// component: ClearingDashboardComponent
loadChildren: () => new Promise(resolve => {
(require as any).ensure([],
require => {
resolve(require("./dashboard/dashboard.module").DashboardModule);
},
"dashboard");
})
The events are no longer propogated down.
I suspect that a different service instance is actually being used.
How do I share the pub/sub downwards to the lazy loaded subsidiaries?
providedin app.module it might not be a singleton... - Jim