Reputation: 221
Here is my actual error:
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'.
Here is the code of lake-info
:
import { Lake } from './lake';
export const LAKES: Lake[] = [
{ name: 'Manitoba'},
{ name: 'Khanka'}
];
Here is the code for 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;
}
}
Here is the code for lake.ts
:
export class Lake {
name: string;
}
I am following this tutorial on the Angular website. My lake-info
file is based on this file.
Let me know if I need to add more details.
Upvotes: 0
Views: 915
Reputation: 495
I try your code in plnkr and that's ok.
https://plnkr.co/edit/kW6B5VSxcmrwQiyQshQT?p=preview
Could you move your project code into plnkr and share to me?
Maybe be the reason of your compile error is the import order (I'm not sure, just guess).
Try drag a topology graph of file import and check if is a cycle in the graph.
In the case of my plnkr the graph is like below and there is no cycle (Cycle import is not unallowed but it's easy to cause problem):
lake.ts <- lake-info.ts
^ ^ ^ ^
| | | |
| lake.service |
| ^ |
| | |
app.component.ts
Upvotes: 0
Reputation: 3232
define a file in lake.ts in same folder and add this code:
export class Lake {
constructor(public id = 0, public name = '') { }
clone() { return new Lake(this.id, this.name); }
}
You can customize this according to your requirement.
Upvotes: 1