Angular - Filter to remove blank strings from array

后端 未结 4 525
甜味超标
甜味超标 2021-01-16 01:46

I have an object of arrays... The array can contain blanks, how can i create an ANgular filter to remove the blanks to determine the length of the array?

$sc         


        
4条回答
  •  Happy的楠姐
    2021-01-16 02:23

    var app = angular.module('app', []);
    app.filter('myFilter', function() {
    
      return function(input) {
        var newInput = [];
        angular.forEach(input, function(item) {
          console.log(item);
          if (item != "") newInput.push(item);
        });
        return newInput;
      };
    });
    
    
    app.controller('fCtrl', function($scope) {
    
      $scope.myData = [
        ["1", "1", "4", "4", "N", "4", "6", "8", "", "", "", "", "", "", "", "", "", ""],
        ["2", "2", "4", "6", "0", "6", "5", "4", "2", "", "8", "", "", "", "", "", "", ""],
        ["2", "3", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""],
        ["3", "F", "D", "3", "5", "1", "D", "5", "", "", "", "", "", "", "", "", "", ""],
        ["1", "V", "4", "4", "3", "2", "1", "1", "4", "", "", "", "", "", "", "", "", ""],
        ["4", "5", "8", "6", "4", "2", "8", "7", "1", "1", "2", "", "", "", "", "", "", ""],
        ["4", "4", "R", "F", "D", "8", "4", "2", "4", "8", "7", "4", "8", "", "", "", "", ""],
        ["D", "5", "F", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""],
        ["1", "4", "1", "3", "4", "B", "D", "G", "", "", "", "", "", "", "", "", "", ""]
      ];
    
    
    
    
    });
    
    
    
    {{data | myFilter }}
    Show if length greater than 10
    Show if length greater than 15

提交回复
热议问题