0.0.2 ā€¢ Published 4 years ago

ngx-nullish v0.0.2

Weekly downloads
7
License
MIT
Repository
github
Last release
4 years ago

NgxNullish

npm version downloads count github-ci

āš’ Angular Structural Directive which replace *ngIf by Nullish Coalescing operator.

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.

Features

  • :white_check_mark: Returns falsy only for null and 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>

šŸ¤ Contributing

Contributions, issues and feature requests are welcome! Feel free to check issues page.

Show your support

Give a ā­ļø if this project helped you!

License

The MIT License @ 2020