gpt4 book ai didi

Angular 7 : 'Cannot find name ' '

转载 作者:太空狗 更新时间:2023-10-29 18:22:04 25 4
gpt4 key购买 nike

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

最佳答案

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

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

关于 Angular 7 : 'Cannot find name ' ',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55223676/

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