ui-sref无法正确渲染

时间:2015-10-21 17:52:53

标签: angularjs

  .state('app.post', {
    url: "/post/:postId",
    views: {
      'menuContent' :{
        templateUrl: 'templates/postPages/viewPost.html',
        controller: 'ViewPostController'  
      }
    }
  })

  .state('app.post.edit', {
    url: "/edit/:postId",
    views: {
      'menuContent@app' :{
        templateUrl: 'templates/postPages/editPost.html',
        controller: 'EditPostController'  
      }
    }
  })

  .state('app.post.comments', {
    url: "/comments/:postId",
    views: {
      'menuContent@app' :{
        templateUrl: 'templates/postPages/post-comments.html',
        controller: 'PostCommentsController'  
      }
    }
  })  

我有这个

<a class="tab-item" ui-sref="app.post.comments({postId:'{{post.id}}'})">
  <i class="icon ion-chatbox"></i>
  Comment
</a>

渲染如下:

<a class="tab-item" ui-sref="app.post.comments({postId:'306cc780-71db-11e5-b49b-7bdc2a9aa3c7'})" href="#/app/post//comments/">
      <i class="icon ion-chatbox"></i>
      Comment
    </a>

在href中缺少帖子

1 个答案:

答案 0 :(得分:0)

postId的网址中提及app.post就足够url: "/post/:postId",,在app.post.edit&amp; app.post.commentsurl只有/edit/comments postId

因此,在传递ui-sref="app.post.comments({postId: post.id})" 时,它只会与父帖合并。

然后你的ui-sref不应该有插值

href="#/app/post/306cc780-71db-11e5-b49b-7bdc2a9aa3c7/comments"

将呈现为

.state('app.post', {
    url: "/post/:postId",
    views: {
      'menuContent' :{
        templateUrl: 'templates/postPages/viewPost.html',
        controller: 'ViewPostController'  
      }
    }
})

.state('app.post.edit', {
    url: "/edit",
    views: {
      'menuContent@app' :{
        templateUrl: 'templates/postPages/editPost.html',
        controller: 'EditPostController'  
      }
    }
})
.state('app.post.comments', {
    url: "/comments",
    views: {
      'menuContent@app' :{
        templateUrl: 'templates/postPages/post-comments.html',
        controller: 'PostCommentsController'  
      }
    }
}) 

<强>国

$max_id = number_format($max_id, 0, '', '');