After creating a basic class in Angular using the CLI starter, I encountered an issue when trying to use the imported class. Instead of functioning as expected, it returned an empty object. Through troubleshooting, I discovered that simply changing the file name from store to Store in the import statement resolved the issue.
Class Definition:
export class Store {
private cards: Object = {};
private previousId: number = -1;
private addCard(card: Card) {
this.cards[card['id']] = card;
return card['id'];
}
public getCard(id) {
return this.cards[id];
}
public create(text: string) {
// Do some stuff...
}
}
Using the Class:
ngOnInit() {
this.getColumsConfig();
this.store = new Store();
console.log(this.store);
}
Issue Arises with Empty Object:
https://i.stack.imgur.com/NyZiu.png
The file was originally named store.ts and imported like so:
import { Store } from '../../services/store';
The import had to be renamed to the following format for it to work:
import { Store } from '../../services/Store';
https://i.stack.imgur.com/spVkw.png
Any insights on why this renaming was necessary? A search online did not provide any clear answers. File naming discrepancy observed in IDE: