Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular uiRouter open state in new window or tab with stateParams

What I want to do is following in but in a new Tab or new Window:

$state.go('studentsReport', {
       type: $scope.report.type, // string
       selectedStudents: $scope.selectedStudents // array of strings
});

If I did:

var link = $state.href('studentsReport', {
       type: $scope.report.type,
       selectedStudents: $scope.selectedStudents
});

window.open(link, '_blank');`

I would lose the parameters.

Best regards, Marcel

like image 660
molerat Avatar asked May 16 '15 14:05

molerat


1 Answers

You should trying to use this:

/* @ngInject */
function SomeCtrl ($state, $window) {
  $window.open($state.href('stateName', {}, {absolute: true}), '_blank');
}

Note: the /* ngInject */ facilitates automatic dependency injection annotation if using ng-annotate (available in cli, gulp, and grunt flavours)

like image 114
Philipp Andreychev Avatar answered Oct 19 '22 08:10

Philipp Andreychev