【问题标题】:ui-sref nested state with params带有参数的 ui-sref 嵌套状态
【发布时间】:2016-05-24 13:02:33
【问题描述】:
.state('user-profile', {
        url: '/user-profile/:userId', //Parent state
        ...
.state('user-profile.profile',{ //nested
        url:'/profile', 
        ...

如何通过ui-sref“user-profile/123/profile”访问网址

目前我正在尝试这个:

<a ui-sref="(user-profile({userId: currentUser._id})).profile">

这将我引向user-profile/123

【问题讨论】:

    标签: javascript angularjs angularjs-scope angular-ui-router mean-stack


    【解决方案1】:

    你快到了,只需先使用状态名称,然后使用参数传递对象{}

    //<a ui-sref="(user-profile({userId: currentUser._id})).profile">
    <a ui-sref="user-profile.profile({userId: currentUser._id})">
    

    【讨论】:

    • 啊,太简单了!谢了哥们。请问您注释掉的代码和未注释的代码有什么区别吗?
    • 另外,我看到人们使用 ng-click 和 $state.go 达到相同的效果。这是一种不好的做法还是什么?
    • 如果我也有嵌套状态的参数怎么办。我只需要在 userId 之后传递另一个对象吗?我的意思是如果我有 /profile/:someId?
    • 有一个工作的 plunker,它应该会给你所有的答案;)另外,ng-click 可以用于动态的东西......但一般来说,如果可能的话 - ui-sref 是首选: plnkr.co/edit/JuaUiJ3ySdtvl5VsbTAi?p=preview
    • 非常感谢。忘记升级了
    猜你喜欢
    • 2014-04-08
    • 2016-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-26
    • 2016-01-04
    • 2015-05-13
    • 1970-01-01
    相关资源
    最近更新 更多