I stucked. I am doing example Angular application from one of the books, where are sometimes mistakes in the code. And I can not find solution for one of them.
After running the app, I am getting an error:
ERROR in src/app/app.component.ts:2:25 - error TS2307: Cannot find module 'app/Athlete' or its corresponding type declarations.
2 import { Athlete } from "app/Athlete";
My code is below. tsconfig.json:
{
"files": [],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.spec.json"
},
]
}
app.component.ts:
import { Component } from '@angular/core';
import { Athlete } from "app/Athlete";
@Component({
selector: 'app-root',
template: `<h1>Pięciu najlepszych zawodników w Kona</h1>
<app-athlete-list (selected)=showDetails($event)>Wczytywanie listy zawodników...</app-athlete-list>
Wybrałeś: {{selectedAthlete}}`
})
export class AppComponent {
selectedAthlete: string;
constructor (){
this.selectedAthlete="żaden";
}
showDetails(selectedAthlete: Athlete) {
this.selectedAthlete=selectedAthlete.name;
}
}
app.module.ts:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { AppComponent } from './app.component';
import { AthleteService } from './athlete.service';
import { AthleteListComponent } from './athlete-list.component';
import { AthleteComponent } from './athlete.component';
@NgModule({
declarations: [
AppComponent,
AthleteListComponent,
AthleteComponent,
],
imports: [
BrowserModule,
FormsModule,
HttpClientModule
],
providers: [AthleteService],
bootstrap: [AppComponent]
})
export class AppModule { }
athlete.ts:
export class Athlete {
name: string;
country: string;
time: string;
}
NOTE: Please note, that athlete.ts
is in the same directory as app.component.ts
.
I tried already this fix, but did not work. And could not find anything else. I will appreciate for your help.