funky-framadate-front/src/app/core/services/url.service.ts

27 lines
785 B
TypeScript
Raw Normal View History

2020-05-05 18:17:12 +02:00
import { Injectable } from '@angular/core';
2020-05-12 19:16:23 +02:00
import { ActivatedRoute } from '@angular/router';
2020-05-05 18:17:12 +02:00
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> {
2020-05-12 19:16:23 +02:00
// TODO: behavior improvement needed.
// check if pollService currentPolls slug match the url : if yes, dont fetch again.
2020-05-05 18:17:12 +02:00
this.loaderService.setStatus(true);
const wantedSlug: string = this.route.snapshot.firstChild.firstChild.url[1].path;
2020-05-12 19:16:23 +02:00
await this.pollService.getPollBySlug(wantedSlug);
2020-05-05 18:17:12 +02:00
this.loaderService.setStatus(false);
}
}