Hello,
I am doing an app that uses models. These models define objects that can correspond either to database or json send by a server. I have two providers, one for the connexion with server and one other for the connexion with database. I have class like this :
export class fooModel {
constructor(public Id: number, public bar: number) { }
getById(server: ServerProvider, id: number): Promise<any> {
server.http.post(`${server.UrlServer}/foo}`, {id: id})
.toPromise().then(data => {
//return serialisation
})
}
}
My problem is, everytime I need to use getbyid, i need to pass server provider (and same for dtb provider). My application was made in Ionic 3 but I recently passed in Ionic 4, so I had to resolve some circular dependencies that was not a problem before. I decided to pass some datas in another provider than server. But it is called in every models and I now see the problem with passing same object everywhere, I have to change all the calls.
Is there a better way to make Ionic models, I mean without passing 3 providers everytime ?
I can migrate all static functions in a “foomodelprovider” but taht means that, for all on static functions of my model, i have to pass the object fooModel to the provider, that sounds strange
Thanks by advance