我正在阅读本教程,并按它所说的做每一件事,直到我到达本教程的这一节,它会抛出这个错误。我已经定义了英雄类,所以我很困惑它为什么要抛给我这个错误。我已经一起重新启动了程序,甚至重新创建了模拟英雄类型的脚本。我使用的是代码,下面是我对这两个文件的代码:
在hero.ts中定义的英雄类:
export class Hero {
id: number;
name: string;
}模拟女英雄:
import { Hero } from './hero'; <----- Error is coming from here
export const HEROES: Hero[] = [
{ id: 11, name: 'Deku' },
{ id: 12, name: 'All Might' },
{ id: 13, name: 'Todoroki' },
{ id: 14, name: 'Naruto' },
{ id: 15, name: 'Ichigo' },
{ id: 16, name: 'Goku' },
{ id: 17, name: 'Vegeta' },
{ id: 18, name: 'Natsu' },
{ id: 19, name: 'Megaman' },
{ id: 20, name: 'One Punch Man' }
];笔记本电脑的文件夹结构:
angular-tour-of-heroes/src/
app/
mock-heroes.ts
heroes/
hero.ts 发布于 2018-03-06 13:56:35
您的解决方案是将路径更改为:
import { Hero } from './heroes/hero';发布于 2018-03-06 13:41:23
是的,因为文件夹结构,所以请按下面的方式更改导入
import { Hero } from './heroes/hero';发布于 2020-05-14 16:59:34
按照角教程:创建英雄界面的说明,hero.ts的位置应该在app文件夹(此处:src/app/hero.ts )和而不是 src/app/heroes/hero.ts中
使用该文件结构,heroes.component.ts中的路径应该是:
import { Hero } from '../hero';
https://stackoverflow.com/questions/49132156
复制相似问题