简体   繁体   中英

Length angular of items in ng-repeat

First, I have this table:

在此处输入图片说明

Where you can see, different colours in the column estado. There are 4 different cases. And i Want to count this different cases. For example in this case there are: Active(green): 1, Vodafone(green+logo): 1, Desactive(Red): 1, Pending(orange):1. But it can change depend of the case.

<div class="input-group">
                      <div>  <h>Instalaciones: {{filteredsites.length}}</h>  <h>Active: {{}}</h> <h>Vodafone: {{}}</h> <h>Desactive: {{}}</h> <h>Pending: {{}}</h></div>

                </div>
<div class="panel-body">
                <div class="row">
                    <div class="col-lg-3">
                        <div >
                            <table class="table table-bordered table-hover table-responsive table-striped dataTable no-footer" data-sort-name="name" data-sort-order="desc">
                                <tr role = "row" class="info text-center">
                                    <th ng-click="order('msisdn')">Número Teléfono</th>
                                    <th ng-click="order('icc')">ICC</th>

                                    <!--th>IMEI</th-->
                                    <th ng-click="order('ActivationStatus')">Estado</th>
                                    <th ng-click="order('sitename')">Instalación</th>
                                    <th ng-click="order('siteaddress')">Dirección</th>
                                    <th ng-click="order('sitecity')">Ciudad</th>
                                    <th ng-click="order('sitezip')">Código Postal</th>

                                    <th ng-click="order('phonedesc')">Modelo Teléfono</th>



                                </tr>


                                <tr class=" text-center" ng-repeat-start="object in filteredsites = (objects | filter:searchText | filter:{parentgroupid:selectedgroup||undefined}) | filter:tableFilter| orderBy:predicate:reverse" ng-click="showDetails = ! showDetails" >
                                    <td>{{object.msisdn}}</td>
                                    <td>{{object.icc}}</td>

                                    <!--td>{{object.ActivationStatus}}</td-->
                                    <td><span ng-init="getStatusCount(object.ActivationStatus)"  ng-show="object.ActivationStatus=='AC' && object.ContractingMode=='0'" class="fa fa-square fa-3x"style="color:lime"></span><span ng-show="object.ContractingMode=='2' && object.ActivationStatus=='AC'  "  ><img src="../img/Vodafone_logo.png" width="40" height="40" style="background-color: lime"></span><span ng-show="object.ActivationStatus=='PA'"  class="fa fa-square fa-3x"style="color:yellow"></span><span ng-show="object.ActivationStatus=='DE'" class="fa fa-square fa-3x"style="color:red"></span></td>
                                    <td>{{object.sitename}}</td>
                                    <td>{{object.siteaddress}}</td>
                                    <td>{{object.sitecity}}</td>
                                    <td>{{object.sitezip}}</td>
                                    <td><span ng-show="object.phonedesc==''"></span><span ng-show="object.phonedesc=='Desconocido'">Desconocido</span><span></span>{{getPhoneModel(object.phonedesc)}}</td>
                                </tr>

                           </table>
                        </div>
                        <!-- /.table-responsive -->




                    </div>
                    <!-- /.col-lg-4 (nested) -->

                    <!-- /.col-lg-8 (nested) -->
                </div>

And the controller:

var app = angular.module('dashboard', ['ui.bootstrap']);

app.controller('dashboardController', function ($scope, $http, $modal) {
    $scope.objects = [];
    $scope.grupos = [];
    $scope.longitud = [];
    $scope.eventos = [];



    var URL = "/api/auth/logout";
    var URLOperation = "/api/sites";
    var URLModel = "http://localhost:81/api/phonelist/";
$scope.getStatusCount= function (status){
   // console.log(status);

    var active = 0;
    active++;
    console.log(active);
    angular.forEach(status ,function(obj) {
        if (obj.status == status) {
            console.log(obj.status);
            console.log(status);
            console.log(active);
            active++;
            console.log(active);
        } });


}


//Funci?n que devuelve las instalaciones de un usuario
    $http.get(URLOperation, $scope)
            .success(function (data) {
                var groups = data;
                angular.forEach(groups, function (group) {
                    var group2 = group;
                    angular.forEach(group2.sites, function (group3) {
                        $scope.longitud.push(group3);
                        $scope.objects.push(group3);
                        $scope.predicate = 'msisdn';
                        $scope.reverse = true;
                        $scope.order = function (predicate) {
                            $scope.reverse = ($scope.predicate === predicate) ? !$scope.reverse : false;
                            $scope.predicate = predicate;
                        };
                    })
                });
            })
            .error(function (data) {
                window.alert('Something Wrong...');
            });




});

If someone can help me the count the different ActivationStatus cases i will appreciated.

You pretty much had it correct? I worked on your example in plunker and it worked right off the bet?

ng-show="object.ActivationStatus=='AC' && object.ContractingMode=='0'"

Seemed to be working for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM