I'm working on micro frontends. and I'm passing one object value from one mfe to another ( say mfe1 to mfe2 ) using Behavior subject (observable) in service.
when i pass the value from mfe1, the object is storing the value. but when i subscribe to the same observable from mfe2, the value is null.
mfe1
navigateFromCatalog(selectedObject: ConnectionList, screen: string): void {
this.analyticsDataService.changeMessage(selectedObject);
if (screen === 'analytics') {
this.router.navigate(['/advisory/analytics']);
} else {
this.router.navigate(['/advisory/modelling']);
}
}
analyticsDataService
export class AnalyticsDataService {
private messageSource = new BehaviorSubject(null);
currentMessage = this.messageSource.asObservable();
constructor(){}
changeMessage(message: Object) {
this.messageSource.next(message);
console.log("msg changed : ",this.messageSource); // the value is stored.
}
mfe2
this.analyticsDataService.currentMessage.subscribe((selectedObject) => {
console.log("current obj : ", selectedObject) // the value is null
}))
webpack file of mfe1
const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
const mf = require("@angular-architects/module-federation/webpack");
const path = require("path");
const share = mf.share;
const sharedMappings = new mf.SharedMappings();
sharedMappings.register(
path.join(__dirname, '../../tsconfig.json'),
[
'@shared'
]);
module.exports = {
output: {
uniqueName: "advisory",
publicPath: "auto"
},
optimization: {
runtimeChunk: false
},
resolve: {
alias: {
...sharedMappings.getAliases(),
}
},
experiments: {
outputModule: true
},
plugins: [
new ModuleFederationPlugin({
library: { type: "module" },
// For remotes (please adjust)
name: "advisory",
filename: "advisoryremoteEntry.js",
exposes: {
'./Advisory': './projects/advisory/src/app/advisory/advisory.module.ts',
},
// For hosts (please adjust)
remotes: {
"analytics" : "http://localhost:4202/analyticsremoteEntry.js",
}
webpack file of mfe2
const sharedMappings = new mf.SharedMappings();
sharedMappings.register(
path.join(__dirname, '../../tsconfig.json'),
[
'@shared'
]);
module.exports = {
output: {
uniqueName: "analytics",
publicPath: "auto"
},
optimization: {
runtimeChunk: false
},
resolve: {
alias: {
...sharedMappings.getAliases(),
}
},
experiments: {
outputModule: true
},
plugins: [
new ModuleFederationPlugin({
library: { type: "module" },
// For remotes (please adjust)
name: "analytics",
filename: "analyticsremoteEntry.js",
exposes: {
'./Analytics': './projects/analytics/src/app/analytics/analytics.module.ts',
},
Need help . Why is the value null??