Attaching click to anchor tag in angular

前端 未结 13 1669
臣服心动
臣服心动 2020-12-13 12:02

I am trying to attach click event to anchor tags (coming from ajax) and block the default redirection. How can I do it in angular ?



        
13条回答
  •  臣服心动
    2020-12-13 13:01

    I've been able to get this to work by simply using [routerLink]="[]". The square brackets inside the quotes is important. No need to prevent default actions in the method or anything. This seems to be similar to the "!!" method but without needing to add that unclear syntax to the start of your method.

    So your full anchor tag would look like this:

    Your Link
    

    Just make sure your method works correctly or else you might end up refreshing the page instead and it gets very confusing on what is actually wrong!

提交回复
热议问题