Reputation: 1
i got this code:
ngOnInit(): void {
this.getEmployees();
this.employeesService
.reloadEmployees()
.subscribe(() => this.getEmployees());
this.employeesService.searchValue$
.subscribe(value => this.employeesService.searchEmployees(value)
.subscribe(el => this.allEmployees = el));
}
Do you guys think that I can simplify that code? What should I do? I need to reduce that subscriptions, because at this point it doesnt look great
Upvotes: 0
Views: 76
Reputation: 2361
you should avoid to subscribe inside another subscription. You can sole it like this:
this.employeesService.searchValue$.pipe(
concatMap(value => this.employeesService.searchEmployees$(value))
).subscribe(el => this.allEmployees = el);
Upvotes: 1