hussain
hussain

Reputation: 7103

How to ignore specific data for table that is using angular ng-repeat?

I have gitignore in one of my log directory now i wanted to display all the file names from that directory but .gitignore is also displaying how can i ignore that file using ng-repeat for table and display rest of the files ?

main.html

<table>
    <tr ng-repeat="file in filename_data">
        <td>{{ file }}</td>
        <td><button type="button" class="btn btn-primary" ng-click="downloadServerFile(file)">download</button></td>
    </tr>
</table>

ctrl.js

$scope.filename_data = [".gitignore","server.log","server1.log"];

Upvotes: 1

Views: 72

Answers (2)

Sean Parsons
Sean Parsons

Reputation: 762

Filter the array before you start looping over it.

arr = [".gitignore","server.log","server1.log"].filter(x => x != '.gitignore')

Upvotes: 0

S Panfilov
S Panfilov

Reputation: 17551

Several options:

  1. You can move .gitignore file to the root and specify path to you folder inside your .gitignore;

  2. You can create a Angular's custom filter and drop away filenames started with .

Like this:

<tr ng-repeat="file in filename_data | myfilter">

Take a look at this article. But be careful with modifying arrays in angular's filters. It's perhaps a bad idea

Updated:

  1. Of course you can use es5's native filter for array:

JS:

$scope.filename_data = $scope.filename_data.filter(function(value){
  return value.indexOf('.') !== 0;
})

here you can find the docs

Upvotes: 2

Related Questions