我正在使用 Angular 11 和 Webpack 5 开展一个新项目。我的工作基于 Manfred Steyer 的Module Federation Plugin Example repo,它使用 Angular CLI。我不知道如何从我的两个应用程序之间共享的本地 Angular 库共享单例服务。
我会尽力解释我的设置.. 真的很抱歉这会持续多久。
root
package.json
projects/
shell/
src/app/
app.module.ts
app.component.ts
webpack.config.ts <-- partial config
mfe1/
src/app/
app.module.ts
app.component.ts
webpack.config.ts <-- partial config
shared/
src/lib/
global.service.ts
package.json <-- package.json for lib
Run Code Online (Sandbox Code Playgroud)
两个 app.component.ts 文件是相同的
import {GlobalService} from 'shared';
@Component({
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {
constructor(shared: SharedService) {}
}
Run Code Online (Sandbox Code Playgroud)
global.service.ts
import { Injectable } from '@angular/core'; …Run Code Online (Sandbox Code Playgroud)