0

I use this code to take the names of tasks into my array barChartLabels.

public lineChartLabels: Label[] = [];

this.tasks.pipe(map(x => x.map(x => x.id))).toPromise().then(id => this.lineChartLabels.push(id))

The code is still working but there is a little problem with it. In fact it copy all names into the first index of lineChartLabels. I expect each name to be written in its own index of the array. How can i change the code to put each name in a single index?

1 Answer 1

1
  1. There is no need to convert the observable to promise. Infact, toPromise() is being discontinued in RxJS v8. Use subscribe instead.

  2. Instead of pushing the array into another array, you'd simply need to assign it.

public barChartLabels: Label[] = [];

this.tasks.pipe(
  map(t => t.map(t => t.name))
).subscribe(
  names => this.barChartLabels = names
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.