ngx-nullish
Version:
šØ Angular Structural Directive which replace *ngIf by Nullish Coalescing operator
80 lines (54 loc) ⢠1.89 kB
Markdown
# ngx-nullish
[](https://www.npmjs.com/package/ngx-nullish)
[](https://badge.fury.io/js/ngx-nullish)
[](https://www.npmjs.com/package/ngx-nullish)
[](https://packagephobia.com/result?p=ngx-nullish)
[](https://piecioshka.mit-license.org)
[](https://github.com/piecioshka/ngx-nullish/actions/workflows/testing.yml)
šØ 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`, `''`
## Usage
Installation:
```bash
npm install ngx-nullish
```
1. Import deps
```javascript
import { NgxNullishModule } from 'ngx-nullish';
@NgModule({
imports: [
...
NgxNullishModule
],
...
})
export class AppModule { }
```
2. Update template
```html
<p *ngIf="numbers$ | async as num">
{{ num }}
</p>
```
replace to:
```html
<p *ngxNullish="numbers$ | async as num">
{{ num }}
</p>
```
## Deployment
Please run a script:
```bash
./scripts/deploy.sh
```
## License
[The MIT License](https://piecioshka.mit-license.org) @ 2020