AngularJS嵌套Ng重复计数器递减

时间:2013-12-05 23:31:32

标签: javascript angularjs angularjs-scope angularjs-ng-repeat

我试图在嵌套的AnguarJs ng-repeat中减少一个计数器。我知道这是范围问题,因为外部ng-repeat的增量工作正常,但在内部ng-repeat是我必须减少的地方,这是我遇到问题的地方(没有任何反应)。有没有办法让内部范围增加/减少/影响外部范围?这是我正在使用的代码。

<div class = "col-md-12 section-bg-conversations" ng-repeat="o in form.question | filter:searchText | orderBy:predicate" ng-show="$index<5 || form.showMoreQuestions" >
<!--section for question and option to answer-->
    <span class="pull-left" style="margin-bottom:5px">
        <ul style="color:#107A77; margin-left: -10px; list-style-type:none">
            <li >
                <!--below is only to toggle form view-->
                <h7><strong><a style="color:#107A77;" ng-click="o.Answer = true" ng-show="!o.Answer">Comment</a></strong></h7>
            </li>
            <li>
                <h7 ng-init="replyCounter=o.replyCounter">Replies&nbsp; ({{replyCounter}}) </h7>
            </li>
            <li>
                <h7>
                <a style="color:#107A77;text-size: 6px" 
                    ng-init="followCounter=o.followCounter" ng-click="followConversation(o.id); o.isFollowing=true;
                    followCounter=followCounter+1" ng-show="!o.isFollowing"> 
                    Follow&nbsp;&nbsp; ({{followCounter}}) 
                </a>
                <span ng-show="o.isFollowing">
                    Following&nbsp;&nbsp; ({{followCounter}}) 
                </span>
                </h7>
            </li>
        </ul>
    </span>
    <span ng-show="o.isFollowing">
        <a style='color:gold' ng-init="followCounter = o.followCounter" ng-click="unfollowConversation(o.followId); o.isFollowing = false; 
        followCounter = followCounter-1 " ng-hide="o.unfollowValue">Unfollow</a>
    </span>
    <!--form div below showing only submit and cancel-->
    <div style="margin-top:5px">
            <button class="btn btn-xs btn-primary" ng-init="replyCounter=o.replyCounter" style='background:#107A77' 
            ng-click="submitAnswer(o.id); replyCounter = replyCounter+1;">Submit</button>
            &nbsp;
            <button class="btn btn-xs btn-primary"  style='background:red' ng-click="o.Answer = false" ng-show="o.Answer">Cancel</button>
     </div>
<div class = "col-md-offset-1" style="padding:5px"ng-repeat="a in o.replies" ng-show="$index<3 || o.showMoreReplies">
    <span ng-show="a.isAuthor">
        <a ng-init="replyCounter=o.replyCounter"style='color:red' ng-click="doDelete(a.id); a.deleteValue = true;  
        replyCounter = replyCounter-1">Delete</a>
    </span>
</div>

我还将followCounter作为正在运行的计数器的例子。几乎主要问题是在最后一个内部div中执行ng-repeat =“a in o.replies”并且我不确定如何解决在整个范围内递增/递减计数器的问题。

0 个答案:

没有答案