角度7:“找不到名称”

时间:2019-03-18 14:28:41

标签: angular routing

我正在Angular 7中从事个人投资组合网站的开发,在使路由正常工作时遇到了问题。该网站将打开,但页面上不显示任何内容。如果我注释掉我的路径,则该网站将正确加载。我找不到解决该问题的任何资源。

///这是我在执行ng serve时在命令行上收到的。

    「wdm」: Compiled successfully.
    ERROR in src/app/app.module.ts(20,31): error TS2304: Cannot find name 'Contact'.
    src/app/app.module.ts(21,33): error TS2304: Cannot find name 'Portfolio'.

//这是我的使路由正常工作的代码。

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';

    import { AppComponent } from './app.component';
    import { SideBarComponent } from './side-bar/side-bar.component';
    import { MainContentComponent } from './main-content/main-content.component';
    import { NavigationBarComponent } from './navigation-bar/navigation-bar.component';

    import { RouterModule, Routes } from '@angular/router';
    import { PortfolioComponent } from './portfolio/portfolio.component';
    import { ContactComponent } from './contact/contact.component';


    const appRoutes: Routes = [

        {path: 'contact', redirectTo: '/contact', pathMatch:'full'},
        {path: 'portfolio', redirectTo: '/portfolio', pathMatch:'full'},

        //this seems to be where I get the problem

        { path: 'contact', component: Contact.Component },
        { path: 'portfolio', component: Portfolio.Component }
    ]

    @NgModule({
        declarations: [
        AppComponent,
        SideBarComponent,
        MainContentComponent,
        NavigationBarComponent,
        PortfolioComponent,
        ContactComponent,
    ],

    imports: [
        BrowserModule,
        RouterModule.forRoot(appRoutes,{ enableTracing: true })    
    ],

        providers: [],
        bootstrap: [AppComponent]
    })
    export class AppModule { }

1 个答案:

答案 0 :(得分:2)

请删除“ Contact.Component”和“ Portfolio.Component”中的点 在第20和21行中是这样的:

  { path: 'contact', component: ContactComponent },
  { path: 'portfolio', component: PortfolioComponent }