0

I want to open a link in new tab in angular, but as it is a SPA, if I open any link in new tab (right click > open link in new tab) then the site is opened in a new tab (www.domain.com) but not with the specific route (www.domain.com/some_route).

The link which I want to open in new tab gets the route from the controller using $location.path in ng-click. I cannot use href attribute in the .

Example HTML:

<a ng-click="myCustomPath()">Click Me</a>

Example JS (controller):

$scope.myCustomPath = function(id, slug){
    $location.path('/some_route/id/slug');
}

I don't want to open the link in new using controller or any other js logic. No redirection, no $window.open or anything.

Long story short, I want to open "www.domain.com/some_route/id/slug" just by right clicking on the link.

Akash Agrawal
  • 2,219
  • 1
  • 17
  • 38
  • check this out http://stackoverflow.com/questions/20819399/how-to-open-new-tab-in-browser-by-using-location-angular – Fadi Abo Msalam Apr 03 '17 at 06:18
  • Possible duplicate of [How to open new tab in browser by using $location, angular?](http://stackoverflow.com/questions/20819399/how-to-open-new-tab-in-browser-by-using-location-angular) – Fadi Abo Msalam Apr 03 '17 at 06:18
  • @FadiAboMsalam, no this is not a duplicate question. In the above link (which you shared), he wants to open a link in new tab by clicking on the link. I don't want to do that. If I left click the link then it open on the same page but if I right click on the link and select "open link in new tab" then I want the specific route. Do you understand my problem or should I rephrase it? – Akash Agrawal Apr 03 '17 at 06:22
  • @FadiAboMsalam, read the problem statement carefully before declaring it a duplicate. – Akash Agrawal Apr 03 '17 at 06:24
  • first of all i am so sorry i misunderstood you it is my bad . i think what you are looking for is this $scope.myCustomPath = function(){ $window.open('https://www.google.com', '_self'); } – Fadi Abo Msalam Apr 03 '17 at 07:59
  • I resolved the issue using ng-href – Akash Agrawal Apr 03 '17 at 17:14

0 Answers0