Collections
compact
Drop nullish values while retaining 0 and false.
Use it in your component
Standalone component
import { Component } from '@angular/core';
import { JsonPipe } from '@angular/common';
import { CompactPipe } from 'extra-pipe';
@Component({
standalone: true,
imports: [CompactPipe, JsonPipe],
template: `{{ [0,null,false,""] | compact | json }}`,
})
export class ExampleComponent {
}
Template
{{ [0,null,false,""] | compact | 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 = [
0,
null,
false,
""
] as const;
{{ value | compact | json }}
Rendered output
[
0,
false,
""
]