【发布时间】:2017-08-05 10:05:41
【问题描述】:
页面加载时出现错误:
compiler.es5.js:1690 Uncaught Error: Type LoginComponent is part of the declarations of 2 modules: LoginModule and AppModule! Please考虑将 LoginComponent 移至导入的更高模块 登录模块和应用模块。你也可以创建一个新的 NgModule 导出并包含 LoginComponent 然后将该 NgModule 导入 LoginModule 和 AppModule。
在@NgModule 我有以下声明:
declarations: [AppComponent, LoginComponent, LanguageComponent]
如何解决这个问题?
在文件 app.module 的顶部我有导入:
import { LanguageComponent } from './language/language.component';
import { LoginComponent } from "./login/login.component";
以下部分:
@NgModule({
imports: [
BrowserModule,
FormsModule,
HttpModule,
TranslateModule.forRoot(),
NgbModule.forRoot(),
CoreModule,
SharedModule,
HomeModule,
AboutModule,
LoginModule,
AppRoutingModule,
InMemoryWebApiModule,
LocalStorageModule,
ReactiveFormsModule,
ReCaptchaModule,
TextMaskModule,
MdButtonModule,
MdCheckboxModule
],
declarations: [AppComponent, LoginComponent, LanguageComponent],
providers: [
AuthenticationService,
HiderPipe,
TimerService
],
bootstrap: [AppComponent]
})
【问题讨论】:
-
更多代码肯定会有所帮助
-
组件也需要在 ngModule 的
exports中。 -
并粘贴整个 NgModule
-
看起来很简单,从 AppModule 的声明中删除 LoginComponent,因为它已经是 LoginModule 的一部分。
-
它明确指出
LoginComponent在 2 个模块中声明。我假设该组件只会在LoginModule中使用,因此在AppModule中声明它是没有意义的。从那里删除它。
标签: angular