- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我是 Angular 的新手,我试图在具有以下目录结构的 Angular2 应用程序中分离我的模块。
我在 AppModule 中声明了我的模块和其他组件,但是我在浏览器控制台中收到一个错误 Unexpected HomeModule declared by AppModule
app
--authentication
---- htmls, ts, css
--home
----dashboard
--------html, ts, css
----representativs
--------html, ts, css
----home-routing.module.ts
----home.module.ts
--app.routing.ts
--app.module.ts
应用程序模块.ts
import { routing } from "./app.routing"
import { AppComponent } from './app.component';
import { HomeModule } from "./home/home.module";
@NgModule({
imports: [BrowserModule, routing, HttpModule, ReactiveFormsModule],
declarations: [ AppComponent, HomeModule],
bootstrap: [AppComponent],
providers: [UserAuthenticationService]
})
export class AppModule { }
home.module.ts
import { NgModule } from '@angular/core';
import { DashboardComponent } from './dashboard/dashboard.component';
import { RepresentativesComponent } from './representatives/representatives.component';
import { HomeRoutingModule } from "./home-routing.module";
@NgModule({
imports: [
HomeRoutingModule
],
declarations: [
DashboardComponent,
RepresentativesComponent,
]
})
export class HomeModule { }
home-routing.ts
const homeRoutes: Routes = [
{
path: 'home',
component: HomeComponent,
children: [
{
path: "representatives",
component: RepresentativesComponent
},
{
path: "dashboard",
component: DashboardComponent
},
{
path: "",
redirectTo: "dashboard",
pathMatch: "full"
}
]
}
]
@NgModule({
imports: [
RouterModule.forChild(homeRoutes)
],
exports: [
RouterModule
]
})
export class HomeRoutingModule { }
应用程序路由.ts
import { AuthenticationComponent } from "./authentication/authentication.component";
import { HomeComponent } from "./home/home.component";
const routes: Routes = [
{
path: 'auth/:action',
component: AuthenticationComponent
},
{
path: 'auth',
redirectTo: 'auth/signin',
pathMatch: 'prefix'
},
{
path: '',
redirectTo: 'home',
component: HomeComponent
}
]
export const routing = RouterModule.forRoot(routes);
最佳答案
您需要在 imports
部分正确导入您的 HomeModule
,而不是 declarations
:
@NgModule({
imports: [BrowserModule, routing, HttpModule, ReactiveFormsModule, HomeModule],
declarations: [AppComponent],
bootstrap: [AppComponent],
providers: [UserAuthenticationService]
})
export class AppModule {
}
我推荐this漂亮地解释了@NgModule 的文章
关于Angular 2 - AppModule 声明的意外模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40911841/
我仅在 Kitkat 设备上遇到此崩溃。我的 logcat 在下面。在 getViewModel 处崩溃 Fatal Exception: java.lang.NoClassDefFoundError
我对 Angular 和 .net Core 还很陌生。我正在编写代码来执行 CRUD 操作。我的一个获取项目组件中有以下代码。 import { Component } from '@angular
我对 Angular 和 .net Core 还很陌生。我正在编写代码来执行 CRUD 操作。我的一个获取项目组件中有以下代码。 import { Component } from '@angular
我已经实现了一个拦截器来添加我可以制作 seucred api 的授权 header 。当我在任何应用程序模块中注入(inject)此服务时出现错误//"无法实例化循环依赖!HttpClient ("
I have added this code into my app.module.ts providers: [ AppConfigService, {
我已经创建了一个类似于 Angular 文档中的突出显示指令,但是我无法在 appmodule 中导入的其他模块中使用它。以下是我的 appmodule.ts 文件: import { Browser
我正在阅读有关模块的 Angular 文档,寻找不鼓励在 AppModule 中导入 SharedModule 的行。 我没有找到任何关于此的内容,只是一个 GitHub 问题,指出最好不要导入它。然
我正在尝试将 AngularDart 应用程序放在一起,并且我会在文档中来回切换。 在 AngularDart 官方网站架构页面中,它谈到了最重要的 AppModule AngularDart Arc
我正在开发 Angular 6 项目。自最近几天以来,我陷入了以下问题。请指导。 我的程序基于惰性路由并且也有动态路由。以下代码是我的app-routing.module.ts: const rou
我一直在使用在线教程并创建了一个“还行”的 SPA 数据输入应用程序。 我可以很好地连接到我的 WEB API,但只构建了一个模型,我的 AppModule 已经有几行了。 我正在考虑并使用当前的方法
Angular 2+ 通过以下方式注册提供者: // @NgModule decorator with its metadata @NgModule({ declarations: [...],
我不明白为什么当我有了新的提供商时,我一次又一次地遇到这个错误。当我有任何其他提供商(如地理定位等)时,我遇到此错误: Error: Uncaught Error: Invalid provider
我才刚刚开始学习如何使用 Angular 2 和 Ionic 3.20.0,但现在面临挑战。我正尝试在我的主页中显示产品图片,但该应用程序抛出此错误 ERROR Error: Uncaught (in
如何从延迟加载的模块访问 AppModule 导入? 我的 Angular 10 应用导入 AngularMaterial 和 NXTranslate 模块 进入 AppModule。 NxTrans
在我的应用程序(独立)中,当我需要从 Guice 获取一些对象实例时,我通常这样做: injector = Guice.createInjector(new AppModule()); instanc
我是 Angular 的新手,我试图在具有以下目录结构的 Angular2 应用程序中分离我的模块。 我在 AppModule 中声明了我的模块和其他组件,但是我在浏览器控制台中收到一个错误 Unex
我最近更新了 2.4.1 版本。 "@angular/common": "~2.4.1", "@angular/compiler": "~2.4.1", "@angular/compiler-cli"
我正在尝试在我的 Angular 6 应用程序中实现延迟加载,我所有的 http 调用都是在 FeatureModule(延迟加载)中进行的,但我仍然必须添加 HttpClientModule 在我的
我已经搜索了很多有关此错误的信息,但没有任何有用的信息,这种错误通常有角度地告诉您缺少提供程序的对象是什么,但是这次它给出了 StaticInjectorError(AppModule)[[objec
我有以下代码 @NgModule({ declarations: [ ... ], imports: [ RoutingModule, SharedModule,
我是一名优秀的程序员,十分优秀!