import { Injectable } from '@angular/core'; import { Router } from '@angular/router'; import { HeaderSettingsService } from './header-settings.service'; @Injectable({ providedIn: 'root' }) export class ActiveTabService { pages = { chat: false, agenda: false, publication: false, home: false, gabinete: false, gabineteDetails: false } updatePublications = () => {} constructor( private router: Router, public HeaderSettingsService: HeaderSettingsService) { this.detectActiveTab() this.router.events.subscribe((val) => { this.detectActiveTab() }); } detectActiveTab() { this.setFalseToAllPage(); const pathName = window.location.pathname this.HeaderSettingsService.hideHeader = false 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 if (pathName.endsWith('gabinete-digital')) { this.pages.gabineteDetails = true } } else if (pathName.startsWith('/home/publications')) { this.pages.publication = true if(pathName.includes("/publications/")) { if(this.updatePublications) { this.updatePublications() } } } else if (pathName.startsWith('/home/chat')) { this.pages.chat = true } } setFalseToAllPage() { for( const page in this.pages) { this.pages[page] = false } } }