Angularjs $state open link in new tab
Solution 1:
Update: OK, I just solved it using the following code:
var url = $state.href('myroute', {parameter: "parameter"});
window.open(url,'_blank');
Solution 2:
I just tried this -- apparently, adding target="_blank"
works with ui-sref
:
<a ui-sref="routeHere" target="_blank">A Link</a>
Saves the trouble of adding code to your controller, and gives you the URL on hover as with any normal link. Win-win!
Solution 3:
I had a similar issue, try this if nothing from previous answers work for you.
var url = '#' + $state.href('preview');
window.open(url,'_blank');
So basically while working in localhost, without appending '#'
it was just redirecting to
localhost/preview
, instead of
localhost/Project_Name/#/preview
I'm not taking here about passing the data, just to open $state in new tab.
Solution 4:
It may not work on localhost in the event your app is in a subfolder. I had in fact the same issue.
I have tried online and it worked as expected by using:
<a ui-sref="routeHere" target="_blank">Link</a>