Search code examples
angularjsangularjs-ng-repeatangular-ng-if

ng-if inside ng-repeat is not filtering my array


Hy evryone, im trying to display tabs with a value inside my types array wchich has

[{"label":"wlan1","type":"wlan1"},
 {"label":"br-wlan","type":"br-wlan"},
 {"label":"tun_cas","type":"tun_cas"},
 {"label":"nfacct_bytes","type":"nfacct_bytes"},
 {"label":"wlan0","type":"wlan0"},
 {"label":"lte0","type":"lte0"},
 {"label":"nfacct_packets","type":"nfacct_packets"}]

In my view I dont want to display the types nfacct_bytes and nfacct_packets and for that I was doing:

<tab ng-if="type.label !== 'nfacct_bytes' || type.label !== 'nfacct_packets'" 
     ng-repeat="type in dataGraph.network.types" heading="{{type.label}}"
     select="changeSubTab(type.type)" disable="!tabClick" >                                                                                                

Solution:

<tab ng-if="type.label !== 'nfacct_bytes' && type.label !== 'nfacct_packets'" 
     ng-repeat="type in dataGraph.network.types" heading="{{type.label}}"
     select="changeSubTab(type.type)" disable="!tabClick" > 

Solution

  • I think you need to check like this,

    <tab ng-if="type.label !== 'nfacct_bytes' && type.label !== 'nfacct_packets' "> 
    </tab>
    

    DEMO

    var myApp=angular.module('myApp',[]);
     myApp.controller('thecontroller',function($scope){
           $scope.dataGraph = {};
           $scope.dataGraph.network = {};
             $scope.dataGraph.network.types = [{"label":"wlan1","type":"wlan1"},{"label":"br-wlan","type":"br-wlan"},{"label":"tun_cas","type":"tun_cas"},{"label":"nfacct_bytes","type":"nfacct_bytes"},{"label":"wlan0","type":"wlan0"},{"label":"lte0","type":"lte0"},{"label":"nfacct_packets","type":"nfacct_packets"}];
    });
     
    <!DOCTYPE html>
        <html>
            <head>
              <title>ng-Messages Service</title>
              <script src='https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>
                <script src='https://code.angularjs.org/1.5.0-rc.0/angular.min.js'></script>
            </head>
            <body ng-app="myApp">
                <div ng-controller='thecontroller'>
                <div  ng-repeat="type in dataGraph.network.types">
               <div ng-if="type.label !== 'nfacct_bytes' && type.label !== 'nfacct_packets' "> {{type.label}}
                </div>
                </div>
                </div>
            </body>
        </html>