I'm trying to implement an "open link in new tab" function using $state.go function. It would be awesome if there was smth like:
$state.go('routeHere', { parameter1 : "parameter" }, { reload : true, newtab : true // or smth like target : "_blank" });
Is there any way to do that using AngularJS?
openNewTab = function (url) { $window. open(url, '_blank'); };
To open the link in a new tab, we can use the <a> element by passing a target attribute with a value _blank .
$stateProvider is used to define different states of one route. You can give the state a name, different controller, different view without having to use a direct href to a route. There are different methods that use the concept of $stateprovider in AngularJS.
ui-sref-active can live on the same element as ui-sref / ui-state , or it can be on a parent element. If a ui-sref-active is a parent to more than one ui-sref / ui-state , it will apply the CSS class when any of the links are active.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With