Utilities
pruneEmpty
Remove recursively empty data while preserving zero and false.
Use it in your component
Standalone component
import { Component } from '@angular/core';
import { JsonPipe } from '@angular/common';
import { PruneEmptyPipe } from 'extra-pipe';
@Component({
standalone: true,
imports: [PruneEmptyPipe, JsonPipe],
template: `{{ data | pruneEmpty | json }}`,
})
export class ExampleComponent {
readonly data = { a: "", b: 0, c: false, d: { e: null } };
}
Template
{{ data | pruneEmpty | 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.
No parameters: use []. Locale is controlled separately.
This pipe has no locale override.
Live template data
readonly value = {
"a": "",
"b": 0,
"c": false,
"d": {
"e": null
}
} as const;
{{ value | pruneEmpty | json }}
Rendered output
{
"b": 0,
"c": false
}