使用ngshow传递数组值" ng-show =" likeClicked [{{comment.id}}]"有效与否

时间:2014-04-25 10:21:33

标签: javascript jquery angularjs

我有评论小部件,我正在加载喜欢和不喜欢按钮的所有评论。一旦用户像任何评论我想隐藏像按钮和显示不喜欢按钮。

is it valid  ??

ng-show="likeClicked[{{comment.id}}]

因为我试图在我的代码中使用这样的东西而且它不起作用。

HTML

  <div class="panel-body">
            Comment ::{{comment.commentline}} <br/>
            ID :: {{comment.id}}
           Likes :: {{comment.like}}  
            <button type="button" class="btn btn-default btn-xs" ng-click="incrlikes(comment)" ng-hide="likeClicked[{{comment.id}}]">
            <span class="glyphicon glyphicon-star"></span> Like
            </button>
             <button type="button" class="btn btn-default btn-xs" ng-click="decrlikes(comment)" ng-show="likeClicked[{{comment.id}}]">
            <span class="glyphicon glyphicon-star"></span> DisLike
            </button><br/>

脚本::

 $scope.incrlikes=function(a)
    {
            var selectedIndex=$scope.comments.indexOf( a );

            if(!$scope.likeClicked[$scope.comments[selectedIndex].id])
            {
            console.log('Likes increment for ::'+ $scope.comments[selectedIndex].name);
            console.log( $scope.comments[selectedIndex].id +'with index of name is '+$scope.comments[selectedIndex].name   );
           //            $scope.comments.indexOf(selectedIndex).like=$scope.comments.indexOf(selectedIndex).like+1;
            $scope.comments[selectedIndex].like=$scope.comments[selectedIndex].like+1;
            $scope.likeClicked[$scope.comments[selectedIndex].id]=true;

          }
          else
          {
            console.log('Already like' +     $scope.likeClicked[$scope.comments[selectedIndex].id]); 
          }
    };

对于上面的代码ng-hide,ng-show按钮不起作用?

1 个答案:

答案 0 :(得分:2)

我认为你需要的是

ng-show="likeClicked[comment.id]"