27 lines
785 B
TypeScript
27 lines
785 B
TypeScript
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<void> {
|
||
// 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);
|
||
}
|
||
}
|