@Injectable()
export class JsonProvider {
public plan;
constructor(public http: HttpClient, public file : File) {
this.http.get('../assets/data/arbeidsplan.json').subscribe(data => {
this.plan = data;
});
this.plan = Array.of(this.plan);
}
}
When I insert the code below in my html file, I get the following Runtime Error: "Error trying to diff ‘object Object’. Only arrays and iterables are allowed.
Hi @IonVis123123
You are doing it wrong.The error is clear that your are trying to iterate an object.
Iteration only possible with array.One solution is that push the object in to an array
and Iterate.Use array.push(this.plan);
Thank you for your quick response. I have probably misunderstood you, but when I change my code, I get the runtime error “Cannot read property ‘push’ of undefined”.
@Injectable()
export class JsonProvider {
public plan : any[];
constructor(public http: HttpClient) {
this.http.get('../assets/data/arbeidsplan.json').subscribe(data => {
this.plan.push(data);
});
}
}
ID1, ID2 etc are your object key.
If you want to iterate over it you should use keyvalue pipe or iterate over Object.keys() and access it by “current” value