ui-router - 嵌套状态

时间:2014-10-21 13:33:39

标签: angularjs ionic-framework angular-ui-router

我们有以下代码:

app.js

.state('app.single', {
      url: "/paths/:pathId",
      views: {
        'menuContent' :{
          templateUrl: "templates/path.html",
          controller: 'PathCtrl'
        }
      }
   })

.state('app.single.comments', {
      url: "/comments",
      views: {
        'menuContent' :{
          templateUrl: "templates/comments.html",
          controller: 'CommentsCtrl'
        }
      }
    });
$urlRouterProvider.otherwise('/app/paths');

path.html:

 <a class="tab-item" href="#/app/paths/{{path.pathid}}/comments">
    <i class="icon ion-chatbox"></i>
    View Comments
 </a>

但是,当我点击查看评论时,它不会显示将由templates / comments.html生成的视图。它保留在当前视图/ path /:pathId(参见屏幕截图)

http://i.stack.imgur.com/yH6Aw.png

1 个答案:

答案 0 :(得分:2)

app.js中的代码应该是:

.state('app.single.comments', {
   url: "/comments",
   views: {
     'menuContent@app' :{
       templateUrl: "templates/comments.html",
       controller: 'CommentsCtrl'
     }
   }
 });