import { Injectable } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { LoaderService } from './loader.service'; import { PollService } from './poll.service'; @Injectable({ providedIn: 'root', }) export class UrlService { constructor( private route: ActivatedRoute, private pollService: PollService, private loaderService: LoaderService ) {} public async loadPollFromUrl(): Promise { // TODO: behavior improvement needed. // check if pollService currentPoll’s slug match the url : if yes, don’t fetch again. this.loaderService.setStatus(true); const wantedSlug: string = this.route.snapshot.firstChild.firstChild.url[1].path; await this.pollService.getPollBySlug(wantedSlug); this.loaderService.setStatus(false); } }