我想导入我的 PageNotFoundComponent
来自我的 ui-components
库到我的应用程序的路由器中。
当我导入 UiComponentsModule
进入我的 AppModule
并使用我模板中的组件,一切正常,但以 es6 表示法导入组件失败。
/libs/ui-components/src/lib/ui-components.module.ts
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { ContactCardComponent } from './contact-card/contact-card.component';
import { NotFoundComponent } from './not-found/not-found.component';
import { WhiteLabelFooterComponent } from './white-label-footer/white-label-footer.component';
import { WhiteLabelHeaderComponent } from './white-label-header/white-label-header.component';
@NgModule({
declarations: [
ContactCardComponent,
WhiteLabelFooterComponent,
WhiteLabelHeaderComponent,
NotFoundComponent
],
exports: [
ContactCardComponent,
WhiteLabelFooterComponent,
WhiteLabelHeaderComponent,
NotFoundComponent
],
imports: [CommonModule],
})
export class UiComponentsModule {}
/apps/myApp/src/app/app-routing.module.ts
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { NotFoundComponent } from 'libs/ui-components/src/lib/not-found/not-found.component';
const routes: Routes = [
{
path: '**',
component: NotFoundComponent,
},
];
@NgModule({
exports: [RouterModule],
imports: [RouterModule.forRoot(routes)],
})
export class AppRoutingModule {}
使用类似
import { NotFoundComponent } from 'libs/ui-components/src/lib/not-found/not-found.component';
的导入我收到短绒错误:library imports must start with @frontend/ (nx-enforce-module-boundaries)tslint(1) Submodule import paths from this package are disallowed; import from the root instead (no-submodule-imports)tslint(1) Module 'libs' is not listed as dependency in package.json (no-implicit-dependencies)tslint(1)
当我将导入更改为
import { NotFoundComponent } from '@frontend/ui-components';
时然后我得到错误:Module '"../../../../../../../../../Users/LeitgebF/Projects/KLAITONWeb/frontend/libs/ui-components/src"' has no exported member 'NotFoundComponent'.ts(2305)
那么如何直接从 Nx 中的库中导入组件呢?
最佳答案
我也必须将所需的组件添加到我的桶文件中。这是直接来自 github repo 支持的答案:https://github.com/nrwl/nx/issues/1533
我不明白,为什么我需要 Angular 模块,但我创建了它并导出了桶文件中的其他组件。
关于angular - 如何从库中导入组件(使用 Angular 在 nrwl/nx 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56806124/