angular - 如何从“app/Athlete”导入{ Athlete }?
问题描述
我卡住了。我正在从其中一本书中做示例 Angular 应用程序,代码中有时会出现错误。我找不到其中之一的解决方案。
运行应用程序后,我收到一个错误:
src/app/app.component.ts:2:25 中的错误 - 错误 TS2307:找不到模块“app/Athlete”或其相应的类型声明。
2 从“应用程序/运动员”导入{运动员};
我的代码如下。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 { }
运动员.ts:
export class Athlete {
name: string;
country: string;
time: string;
}
注意:请注意,它athlete.ts
与app.component.ts
.
我已经尝试过这个修复,但没有奏效。并且找不到其他任何东西。我会感谢你的帮助。
解决方案
将其更改为:
import { Athlete } from 'src/app/Athlete';
推荐阅读
- python - 如何使用 sqlite 访问数据库中的数据
- stripe-payments - 如何在 webhook 请求中获取条带客户 ID 和条带帐户 ID
- javafx - JavaFX拖放后我需要单击两次关闭窗口
- reactjs - React 在每次文本输入更改时重新渲染所有表单控件
- python - Python 代码在 Mac 上的 PyCharm 中有效,但在 FreeBSD Jail 中无效
- c++ - 使用 OpenCV 和 C++ 的高斯滤波器
- javascript - Javascript中的数组多维拆分为两个数组
- c - 模仿c中的“cat>”命令(LINUX/UNIX)
- c++ - 构建 docker 映像在本地工作,但在 docker hub 上不起作用 - cmake
- spring-boot - 多模块 liquibase 项目