stateParams参数未定义

时间:2015-10-23 15:56:15

标签: angularjs

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

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

  .state('app.comments.replies', {
    url: "/replies",
    views: {
      'menuContent@app' :{
        templateUrl: 'templates/postPages/replies.html',
        controller: 'ReplyController'  
      }
    }
  })  

内部post-comments.html

<a class="tab-item" ui-sref="app.comments.replies({commentId:comment.id})">
  <i class="icon ion-chatbox"></i>
  Reply
</a>

angular.module("mobApp.controllers")
.controller("ReplyController",function($scope, $http, $location, $ionicModal, $stateParams){
    alert("ReplyController"+$stateParams.commentId);    

此处commentIdundefined

1 个答案:

答案 0 :(得分:0)

我认为你的路线错误url

.state('app.comments.replies', {
    url: "/replies/:commentId",
    views: {
        'menuContent@app' :{
        templateUrl: 'templates/postPages/replies.html',
        controller: 'ReplyController'  
     }
}

您需要在上面parameter中定义url。然后只有角度为它创建适当的url

这是ui-router DOC,了解参数。