首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ui-sref未正确呈现

ui-sref未正确呈现
EN

Stack Overflow用户
提问于 2015-10-21 17:52:53
回答 1查看 48关注 0票数 0
代码语言:javascript
复制
  .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'  
      }
    }
  })  

我有这个

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

它的渲染方式如下:

代码语言:javascript
复制
<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中缺少post。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-21 17:57:30

app.post中的url中提到app.post就足够了,就像url: "/post/:postId",,在app.post.edit & app.post.comments中,应该只有像/edit/comments这样的url

因此,在传递postId时,它只能与父post合并。

则您的ui-sref不应该有内插。

代码语言:javascript
复制
ui-sref="app.post.comments({postId: post.id})"

将呈现为

代码语言:javascript
复制
href="#/app/post/306cc780-71db-11e5-b49b-7bdc2a9aa3c7/comments"

国家

代码语言:javascript
复制
.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'  
      }
    }
}) 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33266061

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档