I searched for solutions to the problem of
core.umd.js:3523 ORIGINAL EXCEPTION: Cannot read property 'fullName' of undefined
The Exception came from Template on getting specific property:
{{project.collaborators["0"]["fullName"]}}
I found some useful answer too.
but I am looking for a way to define a global service which will check each object and replace missing/empty property with default value i.e -
instead of checking in each template's each property and will make code less buggy.
// undefined-obj.service.ts
import { Injectable } from '@angular/core';
@Injectable()
export class UndefinedObjectsGlobalService {
private charecterToReplace: string = '-'; // set defualt value
replaceDefaultCharecter(object: any, charecterToReplace: string): any {
this.charecterToReplace = charecterToReplace;
// create instance vars to store keys and final output
let keyArr: any[] = Object.keys(object),
var dataArr: any[];
// loop through the object,
// pushing values to the return array
keyArr.forEach((key: any) => {
// if key is null at any iteration then replace is with given text
if (key == null){
dataArr.push(object[key] = this.charecterToReplace);
// else push
}else{
dataArr.push(object[key]);
}
});
// return the resulting array
// need to convert is back to object any idea ?
return dataArr;
}
}
as I am new to angular so the class undefinedObjectsGlobalService
may be buggy
please help.