Angular2 – ‘router-outlet’不是已知的元素

前端之家收集整理的这篇文章主要介绍了Angular2 – ‘router-outlet’不是已知的元素前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我创建路径与深层次的路径.我将AdminComponent中的这个组件添加到NgModule中.但刷新页面后,我收到错误
'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.ts和admin.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,ReactiveFormsModule
    ],declarations: [
        ADMIN_DECLARATION
    ],exports: [
        ADMIN_DECLARATION
    ],providers: [
        TranslateService,FormBuilder
    ]
})

export class AdminComponentModule {

}
AdminComponent是AdminComponentModule的一部分,您尚未在AdminComponentModule模块中导入RouterModule:
//  admin.component.ts
import {Component} from "@angular/core";

@Component({
    selector: 'admin',FormBuilder
    ]
})

export class AdminComponentModule {

}
原文链接:https://www.f2er.com/angularjs/142544.html

猜你在找的Angularjs相关文章