$state打开链接在新标签页。

时间:2021-01-28 19:37:17

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实现“在new tab中打开链接”功能。函数。如果有斯姆斯这样的人,那就太棒了:

$state.go('routeHere', {
    parameter1 : "parameter"
    }, {
    reload : true,
    newtab : true // or smth like target : "_blank"
});

Is there any way to do that using AngularJS?

有什么办法用英语来表达吗?

Thanks,

谢谢,

Alex

亚历克斯

6 个解决方案

#1


117  

Update: OK, I just solved it using the following code:

更新:好的,我用下面的代码解决了:

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

#2


48  

I just tried this -- apparently, adding target="_blank" works with ui-sref:

我刚试过——很明显,添加target="_blank"可以使用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!

省去了向控制器添加代码的麻烦,并为您提供与任何普通链接一样的悬停URL。双赢!

#3


5  

It may not work on localhost in the event your app is in a subfolder. I had in fact the same issue.

如果您的应用程序在子文件夹中,它可能无法在本地主机上工作。事实上我也有同样的问题。

I have tried online and it worked as expected by using:

我在网上试过了,用的是:

<a ui-sref="routeHere" target="_blank">Link</a>

#4


4  

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中工作时,没有附加'#',它只是重定向到

localhost/preview

localhost /预览

, instead of

,而不是

localhost/Project_Name/#/preview

localhost / Project_Name / # /预览

I'm not taking here about passing the data, just to open $state in new tab.

我在这里不是要传递数据,只是在new tab中打开$state。

#5


1  

Try this!

试试这个!

<a ui-sref="routeHere({parameter: vm.parameter})" target="_blank"></a>

< ui-sref = " routeHere({参数:vm.parameter })”目标= "平等" > < / >

#6


1  

ui-sref="routeHere" href=""target="_blank"

this code solved my problem.

这段代码解决了我的问题。

use this in an anchor tag.

在锚标记中使用这个。

#1


117  

Update: OK, I just solved it using the following code:

更新:好的,我用下面的代码解决了:

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

#2


48  

I just tried this -- apparently, adding target="_blank" works with ui-sref:

我刚试过——很明显,添加target="_blank"可以使用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!

省去了向控制器添加代码的麻烦,并为您提供与任何普通链接一样的悬停URL。双赢!

#3


5  

It may not work on localhost in the event your app is in a subfolder. I had in fact the same issue.

如果您的应用程序在子文件夹中,它可能无法在本地主机上工作。事实上我也有同样的问题。

I have tried online and it worked as expected by using:

我在网上试过了,用的是:

<a ui-sref="routeHere" target="_blank">Link</a>

#4


4  

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中工作时,没有附加'#',它只是重定向到

localhost/preview

localhost /预览

, instead of

,而不是

localhost/Project_Name/#/preview

localhost / Project_Name / # /预览

I'm not taking here about passing the data, just to open $state in new tab.

我在这里不是要传递数据,只是在new tab中打开$state。

#5


1  

Try this!

试试这个!

<a ui-sref="routeHere({parameter: vm.parameter})" target="_blank"></a>

< ui-sref = " routeHere({参数:vm.parameter })”目标= "平等" > < / >

#6


1  

ui-sref="routeHere" href=""target="_blank"

this code solved my problem.

这段代码解决了我的问题。

use this in an anchor tag.

在锚标记中使用这个。