Html 角度7:错误错误:未捕获(承诺中):错误:StaticInjectorError(AppModule)[MenuWidgetComponent->;TripsMenu]:
在angular 7中,我面临以下问题,我需要在home组件中注入我的MenuWidgetComponent,我已将其导入widget组件并通过index.ts导出。但我还是觉得 我在谷歌上搜索了一下,但没有找到任何解决方案。我的代码中遗漏了什么吗 角度7:错误错误:未捕获(承诺中):错误: StaticInjectorError(AppModule)[菜单WidgetComponent->TripsMenu]: 以上错误,请帮忙 文件夹结构:Html 角度7:错误错误:未捕获(承诺中):错误:StaticInjectorError(AppModule)[MenuWidgetComponent->;TripsMenu]:,html,angular,typescript,angular6,angular7,Html,Angular,Typescript,Angular6,Angular7,在angular 7中,我面临以下问题,我需要在home组件中注入我的MenuWidgetComponent,我已将其导入widget组件并通过index.ts导出。但我还是觉得 我在谷歌上搜索了一下,但没有找到任何解决方案。我的代码中遗漏了什么吗 角度7:错误错误:未捕获(承诺中):错误: StaticInjectorError(AppModule)[菜单WidgetComponent->TripsMenu]: 以上错误,请帮忙 文件夹结构: ApplicationWorkspace >
ApplicationWorkspace >
1. GlobalApp >
- App >
- app.module
- home Component
2. Libs >
- widget >
src >
- MenuWidgetComponent
- widget module
index.ts
索引
export * from './lib/widgets.module';
export * from './lib/menu-widget/menu-widget.component';
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { NxModule } from '@nrwl/nx';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { HomeComponent } from './home/home.component';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { WidgetsModule } from '@gp-angular-workspace/widgets';
@NgModule({
declarations: [AppComponent, HomeComponent],
imports: [
BrowserModule,
NgbModule.forRoot(),
NxModule.forRoot(),
AppRoutingModule,
WidgetsModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {}
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { WidgetWrapperComponent } from './widget-wrapper/widget-wrapper.component';
@NgModule({
imports: [CommonModule],
declarations: [MenuWidgetComponent],
exports: [ModalWidgetComponent]
})
export class WidgetsModule {}
Home.html
<div class="home" background="assets/images">
<pfj-menu-widget></pfj-menu-widget>
</div>
这应该能帮你解决问题:
@NgModule({
declarations: [AppComponent, HomeComponent],
imports: [
BrowserModule,
NgbModule.forRoot(),
NxModule.forRoot(),
AppRoutingModule,
WidgetsModule
],
providers: [],
entryComponents: [
WidgetsModule
],
bootstrap: [AppComponent]
})
任何要注入另一个组件的内容都必须定义为入口组件。这与将组件注入mat对话框相同
请参阅:以了解更多信息。这将帮助您解决问题:
@NgModule({
declarations: [AppComponent, HomeComponent],
imports: [
BrowserModule,
NgbModule.forRoot(),
NxModule.forRoot(),
AppRoutingModule,
WidgetsModule
],
providers: [],
entryComponents: [
WidgetsModule
],
bootstrap: [AppComponent]
})
任何要注入另一个组件的内容都必须定义为入口组件。这与将组件注入mat对话框相同
请参阅:了解更多信息。我错过了在widgets模块中导入TripsMenu
import { TripsMenu } from './menu-widget/trips-menu';
成功了 我错过了在widgets模块中导入TripsMenu
import { TripsMenu } from './menu-widget/trips-menu';
成功了 TripsMenu在源代码中的位置是否可能重复?@HienNguyen我已在widgetsfolder、folder menu widget>menu-widget.component文件和TripsMenu.ts文件widget>src>-MenuWidgetComponent>-1中创建了它。menu-widget.component-2。trips-menu.ts-widget modulery将子组件添加到module.ts定义中的entryComponents。TripsMenu在源代码中的位置可能重复?@hiennguen我在widgetsfolder中创建了它,文件夹内部菜单小部件>menu-widget.component文件和tripsMenu.ts文件小部件>src>-MenuWidgetComponent>-1。menu-widget.component-2。trips-menu.ts-widget modulery将子组件添加到module.ts定义中的entryComponents中。嗨@JoshHarkema,我尝试过同样的方法,但我得到了这个错误,未捕获的错误:WidgetsModule不能用作入口组件。我明天会旋转它,看看我是否能找到它。嗨@JoshHarkema,我尝试了同样的方法,但是我得到了一个错误,未捕获错误:WidgetsModule不能用作入口组件。我明天将对其进行旋转,看看是否可以解决它。