Skip to content

piecioshka/ngx-nullish

Folders and files

NameName
Last commit message
Last commit date

Latest commit

84ba8ca Β· Oct 17, 2024

History

44 Commits
Oct 17, 2024
Oct 16, 2024
Oct 17, 2024
Dec 7, 2022
Oct 14, 2024
Nov 17, 2023
Jun 20, 2020
Jun 20, 2020
Oct 17, 2024
Jun 20, 2020
Oct 17, 2024
Oct 17, 2024
Dec 7, 2022
Jun 20, 2020

Repository files navigation

ngx-nullish

node version npm version downloads count size license github-ci

πŸ”¨ Angular Structural Directive which replace *ngIf by Nullish Coalescing operator.

Give a ⭐️ if this project helped you!

Motivation

Nobody likes "Falsy Values".

When in your stream (RxJS) are numbers (include 0), *ngIf will coerce 0 to false, means UI will not update.

Preview πŸŽ‰

https://piecioshka.github.io/ngx-nullish-demo/

Features

  • βœ… Returns falsy only for: null, undefined
    • *ngIf returns falsy for: null, undefined, 0, -0, false, NaN, ''

Installation

npm install ngx-nullish

Usage

  1. Import deps

    import { NgxNullishModule } from 'ngx-nullish';
    
    @NgModule({
        imports: [
            ...
            NgxNullishModule
        ],
        ...
    })
    export class AppModule { }
  2. Update template

    <p *ngIf="numbers$ | async as num">
        {{ num }}
    </p>

    replace to:

    <p *ngxNullish="numbers$ | async as num">
        {{ num }}
    </p>

Deployment

Please run a script:

./scripts/deploy.sh

License

The MIT License @ 2020