0

I have an angular js app where I put an API link in the UI to which if the user clicks, he or she can enroll for a survey. Everything is fine but the problem is the user is also directed to the API link address that is a new tab opens. I basically want the user to just click it. So in the backend I know the user wants to enroll. But on clicking the link, the user also gets directed to a new tab.

This is my angular js code

<span ng-bind-html="message.link" ng-click="$event.preventDefault();"> </span>

Here it does stop it from going to a new tab but the link itself is not executed. What am I doing wrong?

Souvik Ray
  • 2,899
  • 5
  • 38
  • 70
  • 1
    you're "preventing the event" so the click will be canceled... – Nathan Schwarz Feb 19 '19 at 16:37
  • There must be more code going on than this but have you tried using the `_self` target attribute? – kawnah Feb 19 '19 at 16:37
  • Possible duplicated :https://stackoverflow.com/questions/8454510/open-url-in-same-window-and-in-same-tab – I_Al-thamary Feb 19 '19 at 16:39
  • @kawnah _self target attribute will let the link open on the same tab right? – Souvik Ray Feb 19 '19 at 16:39
  • " I basically want the user to just click it. So in the backend I know the user wants to enroll. But on clicking the link, the user also gets directed to a new tab." there's no (or very little) logic connection between these statements. Why do you think opening in a new tab changes anything about how the backend percieves the link being opened? – Federico klez Culloca Feb 19 '19 at 16:40
  • @SouvikRay I mean thats the default behavior of a link so that shouldn't need to be explicitly stated in the markup...but as the other user pointed out you're doing a `$event.preventDefault();` which makes me think there is more context that needs to be shared. – kawnah Feb 19 '19 at 16:40
  • Use :`window.open(url, )` – I_Al-thamary Feb 19 '19 at 16:41
  • @FedericoklezCulloca Actually I dont't want the user to be transferred to a new tab. You are right it has nothing to do with the backend..it is just that I want the user to stay in the UI. – Souvik Ray Feb 19 '19 at 16:42

1 Answers1

0

If I understand your question right, you don't actually need a link. The easiest way is to just remove the a. Instead, do a paragraph, or any other element and style it as a link. In addition, just set an ng-click function, that will create the request you want to your back end, entirely invisible to the user.

Ivan Dzhurov
  • 187
  • 6