Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 完成ng重复时隐藏按钮_Angularjs - Fatal编程技术网

Angularjs 完成ng重复时隐藏按钮

Angularjs 完成ng重复时隐藏按钮,angularjs,Angularjs,我想在完成时隐藏按钮。但在我的代码中,我无法访问$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="

我想在完成时隐藏按钮。但在我的代码中,我无法访问$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>

  • {{trans.txnDate}} {{trans.txnDescription} {{trans.credit} 信用
显示更多
在执行

后,$index将不可用。您可以通过自定义指令来实现这一点:-

<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);
        };
    })
  • angular.module('myapp',[]) .directive('onLastRepeat',function(){ 返回函数(范围、元素、属性){ if(scope.$last)设置超时(函数(){
    $(“按钮id”).hide()您想得太多了:

    <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

    您无法在ng repeat外访问$index我知道…但不知何故我需要隐藏按钮..是的,您是对的..但无论如何,我如何才能在
  • 外获得ng repeat的计数,以便我可以隐藏按钮您编写的代码将立即隐藏按钮。$last未在源ar上设置雷,它被设置在过滤阵列上。