-1

I have the below code

 routerLink="{{onSelect(id)}}.

this method is being called all the time, and when i click to go to another tab this takes over, is there anyway in angular that this function will be called only when i click or right-click(new Tab)? Thanks in advance!

My code is like this

HTML<a  routerLink="{{onSelect(prod?.key)}}">{{prod?.name}}</a>
Ts.
onSelect(prod){
    setTimeout(() => {
        this.onSelectedEmmiter.emit(prod);
      }, 0);
}
SO i can not use (click) cause i need the option to open new tab in right click.
Using return [`/x/x/] or navigate work only the first time

1 Answers1

0

You are using it wrong . I should be (click)="onSelect(id)" (assuming that onSelect is supposed to respond to used click). Besides that, answer to WHY it is called all the time:

This is because that particular binding is evaluated every time on the change detection cycle. Such cycle is started on every mouse/keyboard event as async task completion.

Antoniossss
  • 31,590
  • 6
  • 57
  • 99