这是我的实际错误:
Failed to compile.
C:/Examples/my-app/src/app/lake.service.ts (4,10): Module '"C:/Examples/my-app/src/app/lake-info"' has no exported member 'LAKES'.下面是lake-info的代码
import { Lake } from './lake';
export const LAKES: Lake[] = [
{ name: 'Manitoba'},
{ name: 'Khanka'}
];以下是lake.service.ts的代码
import { Injectable } from '@angular/core';
import { Lake } from './lake';
import { LAKES } from './lake-info';
@Injectable()
export class LakeService {
getLakes(): Lake[] {
return LAKES;
}
}以下是lake.ts的代码
export class Lake {
name: string;
}我在Angular网站上关注this tutorial。我的lake-info文件是基于this file的。
如果我需要添加更多细节,请让我知道。
发布于 2017-09-22 14:40:24
在同一文件夹中的lake.ts中定义一个文件,并添加以下代码:
export class Lake {
constructor(public id = 0, public name = '') { }
clone() { return new Lake(this.id, this.name); }
}您可以根据自己的需求进行自定义。
发布于 2017-09-22 15:11:23
我在plnkr中尝试了你的代码,这是可以的。
https://plnkr.co/edit/kW6B5VSxcmrwQiyQshQT?p=preview
你能把你的项目代码移到plnkr中并分享给我吗?
也许你编译错误的原因是导入顺序(我不确定,只是猜测)。
尝试拖动文件导入的拓扑图,并检查图中是否存在循环。
在我的plnkr的例子中,图表如下所示,并且没有循环(循环导入不是不允许的,但很容易导致问题):
lake.ts <- lake-info.ts
^ ^ ^ ^
| | | |
| lake.service |
| ^ |
| | |
app.component.tshttps://stackoverflow.com/questions/46358115
复制相似问题