到达路由中的仪表板部分后,一切都停止在localhost上显示。我试过寻找其他答案,但无法弄清楚。我甚至从链接中复制/粘贴代码"你应该在这里"它仍然没有奏效。这些是我在浏览器中看到的错误消息以及我的文件夹结构。我可以根据需要提供代码,但我认为它没用,因为使用教程中的确切代码似乎也没有用。
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: `
<h1>{{title}}</h1>
<nav>
<a routerLink = "/dashboard">Dashboard</a>
<a routerLink="/heroes">Heroes</a>
</nav>
<router-outlet></router-outlet>
`
})
export class AppComponent {
title = 'Tour of Heroes';
}
这是app.module.ts。
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
import { HeroDetailComponent } from './hero-detail.component';
import { HeroesComponent } from './heroes.component';
import { HeroService } from './hero.service';
import { DashboardComponent } from './dashboard.component';
@NgModule({
declarations: [
AppComponent,
DashboardComponent,
HeroDetailComponent,
HeroesComponent
],
imports: [
BrowserModule,
FormsModule,
RouterModule.forRoot([
{
path: 'heroes',
component: HeroesComponent,
},
{
path: 'dashboard',
component: DashboardComponent
},
{
path: '',
redirectTo: '/dashboard',
pathMatch: 'full'
}
])
],
providers: [HeroService],
bootstrap: [AppComponent]
})
export class AppModule { }