Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@klippa/ngx-async-template

Package Overview
Dependencies
Maintainers
4
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@klippa/ngx-async-template

Easily render templates based on the state of a promise: - inactive - pending - success - error

  • 3.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
349
increased by29.74%
Maintainers
4
Weekly downloads
 
Created
Source

NgxAsyncTemplate

Easily render templates based on the state of a promise:

  • inactive
  • pending
  • success
  • error

Install guide

yarn

yarn add @klippa/ngx-async-template

npm

npm install @klippa/ngx-async-template

Import

I recommend importing the module in a generic ui module and then export it from there, so you can use the ngx-async-template everywhere in your app.

import { NgxAsyncTemplateModule } from '@klippa/ngx-async-template';

@NgModule({
	imports: [
		NgxAsyncTemplateModule,
	],
	exports: [
		NgxAsyncTemplateModule,
	],
})
export class UiModule {}

Example


<ngx-async-template [promise]="userPromise">
  <ng-template ngx-async-inactive>
    loading not yet started
  </ng-template>
  <ng-template ngx-async-pending>
    loading
  </ng-template>
  <ng-template ngx-async-success let-users="value">
    result is {{users}}
  </ng-template>
  <ng-template ngx-async-error let-myErrors="errorMessages">
    something went wrong {{myErrors}}
  </ng-template>
  <ng-template ngx-async-all let-myState="status">
    Always rendered, state is {{myState}}
  </ng-template>
</ngx-async-template>

Usage

To render templates, use one or more of the following directives on a ng-template:

  • ngx-async-inactive

  • ngx-async-pending

  • ngx-async-success

  • ngx-async-error

  • ngx-async-all

  • You can extract the value of a successful promise by using let-someVarName="value" where someVarName can be any name you want.

  • To extract errors provided by a promise you can use let-myErrors="errorMessages" where myErrors can be any name you want.

  • You can also extract the status of a promise, which can be helpful if you have a template with multiple directives (<ng-template ngx-async-inactive ngx-async-pending...) with let-myState="status" where myState can be any name you want.

FAQs

Package last updated on 26 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc