In my model class, I have the following methods:
export class Model {
constructor(public model: any, public repository: RepositoryService) {
}
public hasChildren(id: number) {
return this.model.childs && this.model.findIndex((opt) => opt.id == id) == -1;
}
public getChildren(id: number): Promise<any> {
return new Promise((resolve, reject) => {
if (this.hasChildren(id)) {
resolve(this.model.childs);
} else {
this.repository.loadChildren().subscribe((response) => {
resolve(response);
})
}
});
}
}
// Create instance
this.model = new Model(dataModel, this.repositoryService);
When trying to retrieve data or load it if it is not in the model:
this.model.getChildren(value).then((data) => {
console.log(data);
});
I am facing an issue with the
public getChildren(id: number): Promise<any>
method. How can I correctly utilize promises in this context?