After receiving data from my subscription and displaying it, I encounter an issue when calling my function as it returns a "null" value. I apologize for any language errors in my message. Thank you.
this.service.prepareNewVersion().subscribe(data2 => {
console.log("data2 ", data2);
this.service.myBlockPeriod = data2;
console.log(" prepareNewVersion ", this.service.myBlockPeriod);
});
console.log(" before ", this.service.myBlockPeriod);
this.showYearsExec();
private showYearsExec() {
console.log("showYearsExec", this.service.myBlockPeriod);
let list: Array<string> = this.service.myBlockPeriod;
if (list !== null) {
list.forEach(element => {
this.arrayYears.push(element.substring(0, 4));
});
// Remove duplicate years.
let unique = this.arrayYears.filter(function (elem, index, self) {
return index === self.indexOf(elem);
})
// Populate year combo in the view.
this.arrayYears = unique;
// Add to service
this.service.yearsInExec = unique;
}
}