Collections
removeByKey
Remove records matching excluded values.
Use it in your component
Standalone component
import { Component } from '@angular/core';
import { JsonPipe } from '@angular/common';
import { RemoveByKeyPipe } from 'extra-pipe';
@Component({
standalone: true,
imports: [RemoveByKeyPipe, JsonPipe],
template: `{{ items | removeByKey: 'id': [1, 2] | json }}`,
})
export class ExampleComponent {
items = [{id:1,name:'Item 1'},{id:2,name:'Item 2'},{id:3,name:'Item 3'}];
}
Template
{{ items | removeByKey: 'id': [1, 2] | json }}
Try it live.
The output below runs the packed library. Edit data, not code.
Use double quotes for text, or a number, array, object or null.
Ordered parameters: key, excluded. Locale is controlled separately.
This pipe has no locale override.
Live template data
readonly value = [
{
"id": 1,
"name": "Item 1"
},
{
"id": 2,
"name": "Item 2"
},
{
"id": 3,
"name": "Item 3"
}
] as const;
readonly parameter0 = "id";
readonly parameter1 = [1,2] as const;
{{ value | removeByKey: parameter0: parameter1 | json }}
Rendered output
[
{
"id": 3,
"name": "Item 3"
}
]Adding an item creates a new array. Existing records stay untouched.
Component update
items = [...items, { id: nextId, name: 'New item' }];