我创建了一个共享模块来模块化我的应用程序,因此,如果我想使用例如Material组件,可以通过导入将其包含在其他模块中,问题是当我这样做时会出现此类错误{{ 1}}我该怎么解决?过去,没有共享模块,它可以正常工作,但现在没有,并且因为与家庭作业有关,它必须与共享模块一起使用
应用模块
If 'mat-menu' is an Angular component, then verify that it is part of this module.
身份验证模块
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
//My imports
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { UsersDashboardComponent } from './components/users-dashboard/users-dashboard.component';
import { AdminDashboardComponent } from './components/admin-dashboard/admin-dashboard.component';
import { RouterModule } from '@angular/router';
import { HttpClientModule} from '@angular/common/http';
import { HomeAdminComponent } from './auth/home-admin/home-admin.component';
import { HomeComponent } from './auth/home/home.component';
import { CoreModule } from './../app/core/core.module';
@NgModule({
declarations: [
AppComponent,
HomeComponent,
AdminDashboardComponent,
UsersDashboardComponent,
HomeAdminComponent,
],
imports: [
BrowserModule,
AppRoutingModule,
NgbModule,
BrowserAnimationsModule,
RouterModule,
HttpClientModule,
CoreModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
共享模块
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { SharedModule } from '../shared/shared.module';
import { AuthRoutingModule } from './auth-routing.module';
import { HomeComponent } from 'src/app/auth/home/home.component';
import { HomeAdminComponent } from 'src/app/auth/home-admin/home-admin.component';
@NgModule({
declarations: [HomeComponent,HomeAdminComponent],
imports: [
CommonModule,
AuthRoutingModule,
SharedModule,
],
})
export class AuthModule { }
答案 0 :(得分:0)
为避免此问题,您需要在组件作为声明驻留的所有SharedModule
中添加FeatureModules
作为导入。就像您在AuthModule
中所做的一样。导入MaterialModule
的所有物料模块也应以出口形式导出。
答案 1 :(得分:0)
我解决了将SharedModule
导入AppModule
答案 2 :(得分:0)
我建议您在共享模块内部使用的任何模块(在您的情况下为棱角材质)之上创建自己的自定义组件,然后导出这些组件并将共享模块导入任何其他模块中,然后使用这些组件,如果您决定使用其他库而不是棱角材料或希望构建一些自定义设计,这将在将来为您提供帮助。