4

My code looks something like this and there is data-ng-click for anchor tag.

$state.go('routeHere', {parameter : "parameter"} });

I have tried

var url = $state.go('myroute', {parameter: "parameter"});
window.open(url,'_blank');

target="_blank"

But those are not working.

Is there any other way to do that using AngularJS?

Dalorzo
  • 19,834
  • 7
  • 55
  • 102
anil
  • 413
  • 2
  • 5
  • 17
  • 1
    Angular isn't AngularJS, use the correct tags next time please. –  Mar 13 '18 at 08:14
  • You may find the answer here [Angularjs $state.go open link in new tab](https://stackoverflow.com/a/51565518/1959948) – Dalorzo Jul 28 '18 at 04:29

4 Answers4

4

I don't know what you tried, but here's a working example.

myApp.controller('HelloCtrl', function($scope, $state, $window) {
  $scope.newTab = function() {
   var url = $state.href('about');
   $window.open(url,'_blank');
  }
});
Zooly
  • 4,736
  • 4
  • 34
  • 54
1

I think the only problem with your solution is that you are using the wrong method on $state. Use $state.href instead of $state.go. That way $state will compile the URL for you and place in the variable url to use in the call to $window.open.

Correct code should be:

var url = $state.href('myroute', {parameter: "parameter"});
$window.open(url,'_blank');

Also, use $window instead of just window

kumaheiyama
  • 704
  • 1
  • 13
  • 28
0

$state.go is working but you can use also $window.location.href = newUrl;

Houssein Zouari
  • 712
  • 6
  • 18
0

Works for me :

href="{{$state.href(ng_state, {id : ng_id})}}" target="_blank"
120DEV
  • 805
  • 10
  • 8