gpt4 book ai didi

Angular mat-select 和 webpack module federation 事件问题

转载 作者:行者123 更新时间:2023-12-05 02:42:29 29 4
gpt4 key购买 nike

我在 MonoRepo 中有两个 Angular 应用程序,一个 shell 应用程序和一个内容应用程序。外壳应用程序就像一个显示卡片的登录页面,单击它会显示内容应用程序。

在此内容应用程序中,我使用的是 mat-select 控件,它不会在外部单击时关闭面板 -> 问题!似乎外部点击事件被外壳应用程序捕获。如果我在 shell 应用程序中使用 mat-select,一切正常。

这是我的 shell webpack 配置:

const webpack = require("webpack");
const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");

module.exports = {
output: {
publicPath: "http://localhost:4200/",
uniqueName: "home",
},
optimization: {
runtimeChunk: false,
},
plugins: [
new ModuleFederationPlugin({
shared: {
"@angular/core": { eager: true, singleton: true },
"@angular/common": { eager: true, singleton: true },
"@angular/router": { eager: true, singleton: true }
},
}),
],
};

内容webpack配置:

const webpack = require("webpack");
const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");

module.exports = {
output: {
publicPath: "http://localhost:4201/",
uniqueName: "contentModul"
},
optimization: {
runtimeChunk: false,
},
plugins: [
new ModuleFederationPlugin({
name: "content",
library: { type: "var", name: "content" },
filename: "remoteEntry.js",
exposes: {
ContentModule:
"./projects/content/src/app/content/content.module.ts",
},
shared: {
"@angular/core": { eager: true, singleton: true },
"@angular/common": { eager: true, singleton: true },
"@angular/router": { eager: true, singleton: true }
},
}),
],
};

这是我的路线:

    import { NgModule } from "@angular/core";
import { Routes, RouterModule } from "@angular/router";
import { HomeComponent } from "./home/home.component";
import { PageNotFoundComponent } from "./static-pages/page-not-found/page-not-found.component";
import { loadRemoteModule } from "./utils/federation-utils";

const routes: Routes = [
{ path: "", redirectTo: "home", pathMatch: "full" },
{ path: "home", component: HomeComponent },
{
path: "content",
loadChildren: () =>
loadRemoteModule({
remoteName: "content",
remoteEntry: "http://localhost:4201/remoteEntry.js",
exposedModule: "ContentModule",
}).then((m) => m.ContentModule)
},
{ path: "**", component: PageNotFoundComponent }
];

@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule],
})
export class AppRoutingModule {}

你知道遗漏了什么/错了什么吗?

谢谢!

最佳答案

我遇到了完全相同的问题。我遇到的问题与 Angular 模块的导入有关。我在我的微前端中导入了 Angular 的 BrowserModule,这是错误的。该模块只能导入到您的 shell 应用程序的根模块中。

微前端应该只导入 CommonModule 而不是。如果您改为导入 BrowserModule,这将破坏 Angular 运行时并导致错误,例如未正确捕获事件。

关于Angular mat-select 和 webpack module federation 事件问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67610895/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com