My Angular model class has properties that reference the class itself:
export class ItemCategory {
constructor(
public parentCategory?: ItemCategory,
public subCategories?: ItemCategory[],
public name?: string,
public description?: string
) { }
}
When I try to compile my Angular code, I encounter the following error:
ERROR in src/app/models/entities/itemCategory.model.ts(9,14): error TS2395: Individual declarations in merged declaration 'ItemCategory' must be all exported or all local.
src/app/models/entities/itemCategory.model.ts(28,10): error TS2395: Individual declarations in merged declaration 'ItemCategory' must be all exported or all local.
src/app/models/entities/itemCategory.model.ts(28,10): error TS2440: Import declaration conflicts with local declaration of 'ItemCategory'.
Is there a way to properly reference the class within itself?
Edit: files utilizing this class
src\app\models\services\itemCategory.service.ts
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { ItemCategory } from "../entities/itemCategory.model";
@Injectable({providedIn: 'root'})
export class ItemCategoryService {
constructor(private http: HttpClient) { }
public getAll() : Observable<ItemCategory[]> {
return this.http.request<ItemCategory[]>("get", `api/ItemCategory`, { body: null });
}
public get(id: number) : Observable<ItemCategory> {
return this.http.request<ItemCategory>("get", `api/ItemCategory/${id}`, { body: null });
}
public add(itemCategory: ItemCategory) : Observable<number> {
return this.http.request<number>("post", `api/ItemCategory`, { body: itemCategory });
}
public update(id: number, itemCategory: ItemCategory) : Observable<number> {
return this.http.request<number>("put", `api/ItemCategory/${id}`, { body: itemCategory});
}
public delete(id: number) : Observable<void> {
return this.http.request<void>("delete", `api/ItemCategory/${id}`, { body: null });
}
}
src\app\models\repository.ts
import { Injectable } from '@angular/core';
import { ItemCategory } from "./entities/itemCategory.model";
import { ItemCategoryService } from "./services/itemCategory.service";
@Injectable()
export class Repository {
constructor(
private itemCategoryService: ItemCategoryService
) {
this.itemCategoryService.getAll().subscribe(response => this.itemCategories = response);
}
itemCategories: ItemCategory[];
}