I am new in angular I am trying to change the state of my button in the navbar, taking into consideration the navigation route, however when clicking my button I select all the other buttons including the button pressed.
Here I have my method which I call on the button:
private status = false;
selectOnMenu(event) {
const urlBase = this.location.path();
if (urlBase === '/documents/index/my') {
this.status = !this.status;
} else if (urlBase === '/documents/index/sending') {
this.status = !this.status;
} else if (urlBase === '/documents/index/receiving') {
this.status = !this.status;
} else if (urlBase === '/documents/index/received') {
this.status = !this.status;
} else if (urlBase === '/documents/index/finished') {
this.status = !this.status;
} else {
this.status = status;
}
}
and this is the menu of my buttons:
<div class="btn-group" role="group" aria-label="...">
<a class=" btn btn-square" (click)="selectOnMenu($event)" [ngClass]="status ? 'active' : ''" routerLink="/documents/index/my">MIS DOCUMENTOS</a>
<a class=" btn btn-square" (click)="selectOnMenu($event)" [ngClass]="status ? 'active' : ''" routerLink="/documents/index/sending">PENDIENTES POR DESPACHAR</a>
<a class=" btn btn-square" (click)="selectOnMenu($event)" [ngClass]="status ? 'active' : ''" routerLink="/documents/index/receiving">PENDIENTES POR RECEPCIONAR</a>
<a class=" btn btn-square" (click)="selectOnMenu($event)" [ngClass]="status ? 'active' : ''" routerLink="/documents/index/received">RECEPCIONADOS</a>
<a class=" btn btn-square" (click)="selectOnMenu($event)" [ngClass]="status ? 'active' : ''" routerLink="/documents/index/finished">FINALIZADOS</a>
</div>
I have tried to change my method but it still marks all the buttons when I click, which is incorrect, since only the selected button should be highlighted.