Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
ngx-filter-pipe
Advanced tools
Filter arrays
Angular 2+ pipeline for filtering arrays.
https://vadimdez.github.io/ngx-filter-pipe/
npm install ngx-filter-pipe --save
In case you're using SystemJS
- see configuration here.
Import FilterPipeModule
to your module
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app';
import { FilterPipeModule } from 'ngx-filter-pipe';
@NgModule({
imports: [BrowserModule, FilterPipeModule],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule {}
And use pipe in your component
import { Component } from '@angular/core';
@Component({
selector: 'example-app',
template: `
<div>
<input type="text" [(ngModel)]="userFilter.name" placeholder="name">
<ul>
<li *ngFor="let user of users | filterBy: userFilter">{{ user.name }}</li>
<!-- in case you want to show empty message -->
<li *ngIf="(users | filterBy: userFilter).length === 0">No matching elements</li>
</ul>
</div>
`
})
export class AppComponent {
users: any[] = [{ name: 'John' }, { name: 'Jane' }, { name: 'Mario' }];
userFilter: any = { name: '' };
}
Use $or
to filter by more then one values.
$or
expects an Array
.
In your component:
// your array
const languages = ['English', 'German', 'Russian', 'Italian', 'Ukrainian'];
// your $or filter
const filter = { $or: ['German', 'English'] };
In your template:
<div *ngFor="let language of languages | filterBy: filter">
{{ language }}
</div>
Result:
<div>English</div>
<div>German</div>
In your component:
// your array
const languages = [
{ language: 'English' },
{ language: 'German' },
{ language: 'Italian' }
];
// your $or filter
const filter = {
language: {
$or: ['Italian', 'English']
}
};
In your template:
<div *ngFor="let object of languages | filterBy: filter">
{{ object.language }}
</div>
Result:
<div>English</div>
<div>Italian</div>
Inject FilterPipe
into your component and use it:
class AppComponent {
objects = [
{ name: 'John' },
{ name: 'Nick' },
{ name: 'Jane' }
];
constructor(private filter: FilterPipe) {
let result = this.filter.transform(this.objects, { name: 'J' });
console.log(result); // [{ name: 'John' }, { name: 'Jane' }]
}
}
Run tests
npm test
1.0.2
Inject FilterPipe
into your component and use it:
class AppComponent {
objects = [{ name: 'John' }, { name: 'Nick' }, { name: 'Jane' }];
constructor(private filter: FilterPipe) {
let result = this.filter.transform(this.objects, { name: 'J' });
console.log(result); // [{ name: 'John' }, { name: 'Jane' }]
}
}
FAQs
Angular 5+ pipeline for filtering arrays
The npm package ngx-filter-pipe receives a total of 6,791 weekly downloads. As such, ngx-filter-pipe popularity was classified as popular.
We found that ngx-filter-pipe demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.