My problem is that in setStyle()
function, I have the right values for those 2 arrays, but it won't enter on .map
. Why is that? Where should I call setStyle()
function in order to trigger .map
, if not in ngOnInit
?
ngOnInit() {
this.existingCustomers = this.trackService.refreshExCusts()
this.nonExistingCustomers = this.trackService.refreshNonExCusts()
this.setStyle()
}
setStyle() {
// it enters here
console.log(this.existingCustomers) // has the right value
console.log(this.nonExistingCustomers) // has the right value
this.existingCustomers.map((val) => this.lineStyle.push({ // won't enter here
"customer": val.customer_name,
"color": '#000000'
}))
this.nonExistingCustomers.map((val) => this.lineStyle.push({ // won't enter here
"customer": val.customer_name,
"color": '#ff0000'
}))
console.log(this.lineStyle) // this is empty
}
The value of the arrays:
existingCustomers = [{customer_name: "a"}, {customer_name: "b"}]
nonExistingCustomers = [{customer_name: "c"}, {customer_name: "d"}]
Thank you for your time!