Ral*_*ngo 7 state angularjs angular-ui-router ui-sref
我正在做一个Angular应用程序,其中表的行各有一个按钮,点击这些按钮时,应该为按钮所在的行打开一个新选项卡.
我需要将参数传递到以这种方式创建的新选项卡中.我在状态初始化中声明了参数:
.state('viewlisting', {
url: "/listings/:id",
params: {
'action': '',
},
controller: 'ListingsController',
templateUrl: "partials/listings/view_listing.html"
});
Run Code Online (Sandbox Code Playgroud)
按钮有这样的东西:
ui-sref='viewlisting({id:"+data+", action:"images"})'
Run Code Online (Sandbox Code Playgroud)
传递参数,一切都按预期工作.
//URL: /#/listings/42
$state.params.action //returns "images"
$state.params.id //returns "42"
Run Code Online (Sandbox Code Playgroud)
但是添加target="_blank"到<a>标记会导致$ state.params对象返回以下内容:
//URL: /#/listings/42
$state.params.action //returns ""
$state.params.id //returns "42"
Run Code Online (Sandbox Code Playgroud)
我已经搜索了几个小时,我已经查看了ui-router文档和问题跟踪器,以找到解决我情况但我什么也没找到的东西.
状态参数是否未在target='_blank''ed ui-sref链接上传递?
如果有任何参数应该在当前SPA上下文之外可用(新窗口,新选项卡) - 它必须是URL的一部分.
这将有效:
.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"
});
Run Code Online (Sandbox Code Playgroud)
有关params的更多详细信息如何使用ui-router中的ui-sref将参数传递给控制器
| 归档时间: |
|
| 查看次数: |
10734 次 |
| 最近记录: |