【问题标题】:Angular 7: 'Cannot find name ' 'Angular 7:'找不到名称''
【发布时间】:2019-03-18 14:28:40
【问题描述】:

我正在使用 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 { }

【问题讨论】:

    标签: angular routing


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2019-07-12
      • 2016-01-24
      • 2019-04-06
      • 2022-01-10
      • 1970-01-01
      • 2017-09-14
      • 2021-05-01
      • 2018-03-30
      相关资源
      最近更新 更多