I have a list of buttons that route to various links:
<li nz-menu-item [nzSelected]="isSelected('/home')" routerLink="/home" routerLinkActive="active">
<span title><i nz-icon type="home"></i>Home</span>
</li>
<li nz-menu-item [nzSelected]="isSelected('/news')" routerLink="/news" routerLinkActive="active">
<span title><i nz-icon type="info"></i>News</span>
</li>
I use the directive [nzSelected] and function:
isSelected(route: string): boolean {
return route === this.router.url;
}
to highlight the button to the currently opened route. I have noticed a problem - this makes performance worse, because on each route change, the method 'isSelected' is launched more than 100 times.
What would be the best solution to avoid method execution so much times on each page change?