我正在做一个 Angular 应用程序,其中表格的每一行都有一个按钮,点击这些按钮时,应该为按钮所在的行打开一个新选项卡。
我需要将参数传递到以这种方式创建的新选项卡中。我已经在状态初始化中声明了参数:
.state('viewlisting', {
url: "/listings/:id",
params: {
'action': '',
},
controller: 'ListingsController',
templateUrl: "partials/listings/view_listing.html"
});
按钮有这样的东西:
ui-sref='viewlisting({id:"+data+", action:"images"})'
传入参数,一切都按预期工作。
//URL: /#/listings/42
$state.params.action //returns "images"
$state.params.id //returns "42"
但添加
target="_blank"
到 <a>
tag 导致 $state.params 对象返回以下内容://URL: /#/listings/42
$state.params.action //returns ""
$state.params.id //returns "42"
我已经搜索了几个小时,我查看了 ui-router 文档和问题跟踪器,以寻找解决我情况的问题,但我什么也没找到。
状态参数是否未传递给
target='_blank'
'ed ui-sref
链接?
最佳答案
如果有任何参数应该在当前 SPA 上下文之外可用(新窗口、新选项卡) - 它 必须成为网址的一部分。
这将起作用:
.state('viewlisting', {
// instead of this
// url: "/listings/:id",
// this will keep the action in a new window
url: "/listings/:id?action",
params: {
'action': '',
},
controller: 'ListingsController',
templateUrl: "partials/listings/view_listing.html"
});
有关参数的更多详细信息 How to pass parameters using ui-sref in ui-router to controller
关于angularjs - ui-router : open state in new tab with target ="_blank", 参数丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33232761/