Angular-6路由器出口不是已知元素,模板解析错误

时间:2018-09-27 03:24:46

标签: angular6 router-outlet

app-routing.module.ts

settings.py
import {NgModule} from '@angular/core';
import {RouterModule, Routes} from '@angular/router';
import {PostListComponent} from './post/post-list.component';
const routes: Routes =  [
  { path: '', redirectTo: '/home', pathMatch: 'full' },
  { path: 'posts', component: PostListComponent},

]
@NgModule({
  imports: [ RouterModule.forRoot(routes)],
  exports: [ RouterModule ]
})
export class AppRoutingModule{
}

**app.component.html**
请发表评论以获取相关的有用代码,以获取更多帮助。谢谢

1 个答案:

答案 0 :(得分:0)

我知道我没有将 App-routing.module 导入我的 App.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { HttpClientModule } from '@angular/common/http';
import { AppComponent } from './app.component';
import { PostListComponent } from './post/post-list.component';
import { PostService} from './post/post.service';
import { HomepageComponent } from './homepage/homepage.component';

@NgModule({
  declarations: [
    AppComponent,
    PostListComponent,
    HomepageComponent
  ],
  imports:[
    BrowserModule,
    HttpClientModule,
    **AppRoutingModule**
  ],
  providers: [
    PostService
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }