Angularjs $state open link in new tab
Update: OK, I just solved it using the following code:
var url = $state.href('myroute', {parameter: "parameter"});window.open(url,'_blank');
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!
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.