Javascript 在新窗口或带有stateParams的选项卡中打开状态

Javascript 在新窗口或带有stateParams的选项卡中打开状态,javascript,angularjs,angular-ui-router,Javascript,Angularjs,Angular Ui Router,我想在新选项卡或新窗口中执行以下操作: $state.go('studentsReport', { type: $scope.report.type, // string selectedStudents: $scope.selectedStudents // array of strings }); 如果我这样做了: var link = $state.href('studentsReport', { type: $scope.report.type

我想在新选项卡或新窗口中执行以下操作:

$state.go('studentsReport', {
       type: $scope.report.type, // string
       selectedStudents: $scope.selectedStudents // array of strings
});
如果我这样做了:

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

window.open(link, '_blank');`
我会丢失参数

致以最良好的祝愿,
Marcel

您应该尝试使用以下方法:

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

注意:
/*ngInject*/
如果使用ng annotate(在和Flavors中提供)

使用ng单击链接标签并调用函数,则有助于自动进行依赖项注入注释。在函数中,将参数放入本地存储。然后在app.run中,在(“$stateChangeStart”)上使用$rootScope.$on,检查localstorage是否有参数get params,并使用params调用$state

//在页面控制器中:
var openNewTab=函数(){
localStorage.newTab=JSON.stringify({
州:“你的州”,
参数:{
param1:“someparam1”,
参数2:“someparam2”
}
});                  
窗口。打开(文档。位置。来源);
}
//角度应用程序运行配置:
angularApp.run(函数($state){
if(localStorage.newTab){
var newTab=JSON.parse(localStorage.newTab);
localStorage.removietem(“newTab”);
$state.go(newTab.state,newTab.params);
event.preventDefault();
}
})

打开新选项卡
感谢您的回复,但这不起作用。但我必须说,我没有使用注释/*@ngInject*/,假设它只是一个comment@molerat我必须说,我并没有在函数的第二个参数中设置参数。你应该试着设置他们的。我知道,我设置了他们的,但没有起作用。如果我们说正常的url是,
$state.href('stateName',{test:'bla'},{absolute:true})
应该返回什么url?@molerat没有完全理解您的问题。您可以根据需要配置url:。也许你应该试着读一下这个答案:@molerat在我的例子中url应该是相等的
localhost/#/stateName/bla
:)