I try to make a filter method this method works well but I have an error: cannot convert undefined or null to object that I cannot solve
example json
{
"toto": [
"titi",
"tata"
],
hideString: [], // filter method hide this element
"foo": [
"foobar",
"footix"
]
}
card.components.ts
@Input() toto: ISummary[] = []
getKeys() {
Object.keys(this.toto).filter(key => this.toto[key].lenght > 0)
// in my console I have the following error: cannot convert undefined or null to object
the error comes from this line
}
totoa(keys:string){
return this.toto[key]
}
card.html
<div *ngFor="let keys of getKeys()">
{{keys}}
<div *ngFor="let values of totoa(keys)">
{{values}}
</div
</div
home.components.ts
public result: string = '';
public toto?: Observable<ISummary[]>; // maybe the problem comes from Here I have ternary operator '?'
ngOnInit() {
this.activatedRoute.paramMap.subscribe(params = > {
let bigramme = params.get('bigramme');
this.result = bigramme as string;
getSummary();
}
}
getSummary() {
this.toto = this.sumService.getAllSummary(this.result);
}

this.toto[key]maybe be the cause of itthis.summarykeys.Object.keys(this.toto). you don't needthis.summarykeysjust useObject.keys(yourobject)totois array and keys of array is0,1,...` .