ng-repeat完成后隐藏按钮

时间:2015-02-17 06:37:09

标签: angularjs

我想在ng-repeat完成后隐藏按钮。但在我的代码中,我无法访问$ index值。

任何人都可以给我提示吗?

  <div class="row">
                            <ul class="list-group col-xs-12 col-sm-12 col-md-12">
                              <li class="list-group-item row border-bottom-gray" ng-repeat="trans in transaction.response.transactions|limitTo:count" >
                                <div class="col-xs-8 col-sm-8 col-md-8">
                                  <span class="text-muted">{{trans.txnDate}}</span>
                                  <span>{{trans.txnDescription}} 
                                  </span>
                                </div>
                                <div class="col-xs-4 col-sm-4 col-md-4 text-right">
                                  <strong>{{trans.credit}}</strong>
                                  <span class="text-muted">Credit</span>
                                </div>
                              </li>

                            </ul>
                            <div class="col-xs-12 col-sm-12 col-md-12 text-center"></div>
                            <div style="position: static" class="showMore col-xs-12 col-sm-offset-4 col-sm-4 col-md-offset-4 col-md-4">
                              <button style="position: static" class="btn btn-block btn-default center-block" ng-click="count = count + 9" ng-init="count=9" ng-hide="transaction.response.transactions.length == $index">
                                Show more
                                <span class="caret"></span>
                              </button>

                            </div>
                          </div>

3 个答案:

答案 0 :(得分:0)

</li>

之后,

$ index将无法使用

答案 1 :(得分:0)

您可以通过自定义指令实现此目的: -

<li class="list-group-item row border-bottom-gray" ng-repeat="trans in transaction.response.transactions|limitTo:count" on-last-repeat >

angular.module('myapp', [])  
    .directive('onLastRepeat', function() {
        return function(scope, element, attrs) {
            if (scope.$last) setTimeout(function(){
             $("button_id").hide();  <- provide id of your button. 
            }, 1);
        };
    })

这不是一个好的答案,但它对你有用。

答案 2 :(得分:0)

你正在思考它:

<button style="position: static" class="btn btn-block btn-default center-block" ng-click="count = count + 9" ng-init="count=9" ng-show="count < transaction.response.transactions.length">
    Show more
    <span class="caret"></span>
</button>

无需使用$ index