I have a problem with @if in the Angular template flow syntax.
A value is available in an RxJs Observable. So the async pipe helps and the value is assigned to a variable.
@if (currentPageNumber$ | async; as currentPageNumber) {
// currentPageNumber is number
For value 0 the if statement is not valid. So I exclude only null values… but now the value of currentPageNumber is boolean.
@if ((currentPageNumber$ | async) !== null; as currentPageNumber) {
// currentPageNumber is boolean
How can I check against null but keep my variable with the value of the stream?
the issue you meet is due to the as
when you do (currentPageNumber$ | async) !== null; as currentPageNumber
you affect the result of (currentPageNumber$ | async) !== null
to variable currentPageNumber
in that case the result is a boolean
one way to solve the issue is to let the variable affectation and add an embed if in the first one
@if (currentPageNumber$ | async; as currentPageNumber) {
@if (currentPageNumber !== null) {
}
}