import { Injectable } from '@angular/core'; import { Router } from '@angular/router'; @Injectable({ providedIn: 'root' }) export class ActiveTabService { pages = { chat: false, agenda: false, publication: false, home: false, gabinete: false } constructor(private router: Router) { this.detectActiveTab() this.router.events.subscribe((val) => { this.detectActiveTab() }); } detectActiveTab() { this.setFalseToAllPage(); const pathName = window.location.pathname if(pathName.startsWith('/home/agenda')) { this.pages.agenda = true } else if (pathName.startsWith('/home/events')) { this.pages.home = true } else if (pathName.startsWith('/home/gabinete-digital')) { this.pages.gabinete = true } else if (pathName.startsWith('/home/publications')) { this.pages.publication = true } else if (pathName.startsWith('/home/chat')) { this.pages.chat = true } } setFalseToAllPage() { for( const page in this.pages) { this.pages[page] = false } } }