Hi I'm kinda new in Angular and I have the 7 version. I'm writing an application and I want to know if it's possible to bind a JSON file to a variable.
I have a class like this:
export class Aparment {
id: number;
address: string;
constructor(id: number, address: string) {
this.id = id;
this.address = address;
}
}
In a component I have an array of Apartment and I push some apartment objects in it. What I'm looking for is a way to read all apartment objects stored in a file in /assets/json/apartments.json when I run the application and add an apartment objet into the json file when I push a new object into the array. So far I've read that from typescript 2.9+ we can import and use a json file, but I don't know how to cast it as an array of Apartment and I don't know how to store new elements into it.