Collections
mergeBy
Reconcile partial records with shallow last-field precedence.
Use it in your component
Standalone component
import { Component } from '@angular/core';
import { JsonPipe } from '@angular/common';
import { MergeByPipe } from 'extra-pipe';
@Component({
standalone: true,
imports: [MergeByPipe, JsonPipe],
template: `{{ [{"id":1,"name":"Ana"}] | mergeBy: [{"id":1,"active":true}]: "id" | json }}`,
})
export class ExampleComponent {
}
Template
{{ [{"id":1,"name":"Ana"}] | mergeBy: [{"id":1,"active":true}]: "id" | 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: other, key. Locale is controlled separately.
This pipe has no locale override.
Live template data
readonly value = [
{
"id": 1,
"name": "Ana"
}
] as const;
readonly parameter0 = [{"id":1,"active":true}] as const;
readonly parameter1 = "id";
{{ value | mergeBy: parameter0: parameter1 | json }}
Rendered output
[
{
"id": 1,
"name": "Ana",
"active": true
}
]