ngx-if-empty-or-has-items
This is support library just to help You answer this question 'in angular template how to check if object is empty', 'in angular template how to check if array is empty'.
This is stable version and will change only if angular makes changes to ngIf
ngxIfEmpty - It Checks if value is an empty object, collection, map, or set.
ngxIfNotEmpty, ngxIfHasItems - It Checks if value is an NOT empty object, collection, map, or set.
Also This directives have the same functionality as *ngIf so 'then' 'else' and 'as' syntax also working
Installation
To install this library, run:
$ npm install ngx-
Consuming your library
You can import your library in any Angular application by running:
$ npm install ngx-
and then from your Angular AppModule
:
You can import all 3 modules at the same time or pick one that You need;
;; // Import your library all 3 at the same time:; //Or import them separately: ;;;
SharedModule
If you use a SharedModule that you import in multiple other feature modules, you can export the NgxIfEmptyOrHasItemsModule to make sure you don't have to import it in every module.
This is helper library it uses the same functionality as ngIf but under the hood it uses isEmpty from lodash.
It Checks if value is an empty object, collection, map, or set.
<!-- You can now use your library component in app.component.html -->arr = [] || {}arrayOrObjWithData = ['1'] || {id: 1} You will see this text <!-- You can also use 'as' syntax to store data in variable --> {{obj.name}} You will see it You will see it this is ignored Primary text to show Secondary text to show Alternate text while primary text is hidden
License
MIT © Oleksandr Khymenko