gpt4 book ai didi

Angular2 - 'router-outlet' 不是已知元素

转载 作者:太空狗 更新时间:2023-10-29 16:45:37 26 4
gpt4 key购买 nike

<分区>

我创建了具有深子路径的路由。我添加了 <router-outlet>到我包装到 NgModule 中的 AdminComponent 组件。但是刷新页面后我得到了这个错误:

'router-outlet' is not a known element

可能是因为我忘记将某些模块导入 admin.module.ts

请帮忙。谢谢。

app.routes.ts

export const routes: Routes = [
{
path: '',
component: AppComponent,
children: [
{
path: '',
component: LoginComponent
},
{
path: 'admin',
component: AdminComponent
},
{
path: 'user',
component: UserComponent
},
{
path: 'there',
component: ThereComponent
}
]
}
]

app.module.ts

@NgModule({
imports: [
BrowserModule,
AppRoutes,
FormsModule,
ReactiveFormsModule,
HttpModule,
RouterModule,
TranslateModule.forRoot({
provide: TranslateLoader,
useFactory: (http: Http) => {
return new TranslateStaticLoader(http, './src/assets/i18n', '.json')
},
deps: [Http]
}),
UserComponentModule,
AdminComponentModule,
LoginComponentModule,
ThereComponentModule,
DashboardComponentModule
],
declarations: [
AppComponent
],
providers: [
FormBuilder
],
bootstrap: [AppComponent]
})

admin.component.tsadmin.module.ts

//  admin.component.ts
import {Component} from "@angular/core";

@Component({
selector: 'admin',
template: "<router-outlet></router-outlet>",
})

export class AdminComponent {
constructor() {

}
}

// admin.module.ts
const ADMIN_DECLARATION = [
AdminComponent
];

@NgModule({
imports: [
BrowserModule,
TranslateModule,
FormsModule,
ReactiveFormsModule
],
declarations: [
ADMIN_DECLARATION
],
exports: [
ADMIN_DECLARATION
],
providers: [
TranslateService,
FormBuilder
]
})

export class AdminComponentModule {

}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com