import { Component, OnInit } from '@angular/core'; import { Router } from '@angular/router'; import { Observable } from 'rxjs'; import { Poll } from '../../../core/models/poll.model'; import { PollService } from '../../../core/services/poll.service'; @Component({ selector: 'app-poll', templateUrl: './poll.component.html', styleUrls: ['./poll.component.scss'], }) export class PollComponent implements OnInit { public isLoading = false; public wantedSlug: string; public poll: Observable; public slugFromUrl: string; private readonly urlMatcher: RegExp = new RegExp(/participation\/poll\/(\w+)/); constructor(private router: Router, private pollService: PollService) {} ngOnInit(): void { this.wantedSlug = this.urlMatcher.exec(this.router.url)[1]; this.poll = this.pollService.poll; this.loadPollFromUrl(); } private async loadPollFromUrl(): Promise { this.isLoading = true; await this.pollService.getPollByIdentifier(this.wantedSlug); this.isLoading = false; } }