0

因为我有如下嵌套对象:

提供者(providerId)=>> 帖子(postId)=>> 评论(commentId)=>> 回复(replyId)

因此,当我处于回复的最后一步时,我无法将 providerId 传递给回复步骤。

这里展示了每个步骤中 $stateParams 的工作原理。 在此处输入图像描述

这是回复状态。

$stateProvider
      .state('reply', {
        url: '/blog/providers/{providerId}/posts/{postId}/comments/{commentId}',
        templateUrl: 'app/blog/provider/post/comment/reply/reply.html',
        controller: 'ReplyCtrl'
      });

因此,由于我无法传递任何参数,我收到以下错误:

GET http://localhost:9000/api/providers//posts/5551b281bcaa20002387fb31/comments/5551b3b4bcaa20002387fb32 404 (Not Found)

这就是我在comment.html 中的内容,在回复前一步,以便将参数传递给回复步骤。在这种情况下,我不确定如何检索 providerId,因为我这里没有。

<div ng-repeat="comment in post.comments track by $index" >
.......
<a  ui-sref="reply({providerId: ..., postId : post._id, commentId: comment._id})"></a>

同样在replyCtrl 中,我无法访问我在html 中传递的任何变量,这是我得到的错误。我只是在replyCtrl 中添加了以下几行。

console.log('postId from reply state' , postId);
console.log('commentId from reply state', commentId);

所以这是我收到的错误。

ReferenceError: postId is not defined

有什么帮助可以指导我如何在这里传递参数。

4

1 回答 1

0

这个链接会帮助你:)

在 $stateProvider 中传递参数

于 2015-05-14T06:43:56.537 回答