I am trying to get the second function return value in ngOnInit, but it's giving undefined. If I print SvgImage its printing. I don't know where I did the mistake.
ngOnInit() {
this.userService.displayEvents(this.user_id).subscribe(data => {
this.eventArray = [];
if (data.status == 'success') {
data.result.forEach(obj => {
let item = {
id: obj.id,
user_id: obj.user_id,
name: obj.name,
image: this.getSvgImage(obj.category, obj.color_code),
category: obj.category,
start_date: obj.start_date,
status: obj.status,
};
this.eventArray.push(item);
});
this.displayEvents = this.eventArray;
console.log(this.displayEvents);
}
});
}
getSvgImage(categoryID: any, colorCode: any) {
this.userService.getEventCategory().subscribe((data) => {
let SvgImage: any = "";
if (data.status == "success") {
data.result.forEach(obj => {
if (obj.id == categoryID) {
let color = colorCode.replace("#", "");
let SvgImageReplace = obj.image.split('#').pop().split(';')[0];
SvgImage = obj.image.replace(SvgImageReplace, color);
SvgImage = this.sanitized.bypassSecurityTrustHtml(SvgImage);
}
});
}
return SvgImage;
});
}