Last active
April 4, 2022 10:14
-
-
Save konstantindenerz/dc8e1482f1f017cd8fd6f4bc43dc1edc to your computer and use it in GitHub Desktop.
Use this pipe to provide default values for null values of async pipe. `foo$ | async | nullTo:false`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Pipe, PipeTransform } from '@angular/core'; | |
@Pipe({ | |
name: 'nullTo', | |
}) | |
export class NullToPipe implements PipeTransform { | |
/** | |
* Returns {@link value} or {@link newNullValue} if {@link value} is null. | |
*/ | |
transform<T>(value: T | null, newNullValue: T): T { | |
return value !== null ? value : newNullValue; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment