{"id":19077911,"url":"https://github.com/julienblin/ng-async-event","last_synced_at":"2026-05-07T14:33:06.952Z","repository":{"id":65458020,"uuid":"119400732","full_name":"julienblin/ng-async-event","owner":"julienblin","description":null,"archived":false,"fork":false,"pushed_at":"2018-07-02T20:29:00.000Z","size":134,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-03T04:29:40.705Z","etag":null,"topics":["angular","angular2","angular4","angular5","npm","rxjs","rxjs-observables"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/ng-async-event","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/julienblin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-29T15:25:52.000Z","updated_at":"2020-10-13T17:51:46.000Z","dependencies_parsed_at":"2023-01-24T12:45:31.423Z","dependency_job_id":null,"html_url":"https://github.com/julienblin/ng-async-event","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/julienblin%2Fng-async-event","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/julienblin%2Fng-async-event/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/julienblin%2Fng-async-event/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/julienblin%2Fng-async-event/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/julienblin","download_url":"https://codeload.github.com/julienblin/ng-async-event/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240128935,"owners_count":19752265,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular","angular2","angular4","angular5","npm","rxjs","rxjs-observables"],"created_at":"2024-11-09T02:03:59.237Z","updated_at":"2026-05-07T14:33:04.768Z","avatar_url":"https://github.com/julienblin.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ng-async-event\n\nAngular UI component that simplifies usage of [rx-async-event](https://github.com/julienblin/rx-async-event).\n\n[![Travis](https://travis-ci.org/julienblin/ng-async-event.svg?branch=master)](https://travis-ci.org/julienblin/ng-async-event)\n[![npm](https://img.shields.io/npm/v/ng-async-event.svg)](https://www.npmjs.com/package/ng-async-event)\n\n## Objectives\n\nThis library is a complement to [rx-async-event](https://github.com/julienblin/rx-async-event) that allows the projection of\nthe state management in [rx-async-event](https://github.com/julienblin/rx-async-event) into dedicated, re-usable templates.\n\n## How to use\n\n### Installation\n\n```shell\nnpm i --save ng-async-event\n```\n\n### Import the NgAsyncEventModule in the main app module\n\n```typescript\n@NgModule({\n  declarations: [\n    AppComponent\n  ],\n  imports: [\n    BrowserModule,\n    NgAsyncEventModule\n  ],\n  providers: [],\n  bootstrap: [AppComponent]\n})\nexport class AppModule { }\n```\n\n### Service\n\n```typescript\nimport { Injectable } from '@angular/core';\nimport { HttpClient } from '@angular/common/http';\nimport { AsyncEventObservable, AsyncEventSubject } from 'rx-async-event';\nimport { Post } from './post';\n\n@Injectable()\nexport class AppService {\n\n  private readonly _postEvent$ = new AsyncEventSubject\u003cnumber, Post\u003e();\n\n  constructor(private http: HttpClient) { }\n\n  get postEvent$(): AsyncEventObservable\u003cnumber, Post\u003e {\n    return this._postEvent$.asObservable();\n  }\n\n  /**\n   * Example of managing the life cycle of an HttpClient Observable.\n   */\n  loadPost(id: number) {\n    return this._postEvent$.observe(\n      id,\n      this.http.get\u003cPost\u003e(`https://jsonplaceholder.typicode.com/posts/${id}`));\n  }\n\n  /**\n   * This example manages the life cycle of a Promise instead.\n   */\n  loadPostAsPromise(id: number) {\n    return this._postEvent$.execute(\n      id,\n      (arg) =\u003e this.http.get\u003cPost\u003e(`https://jsonplaceholder.typicode.com/posts/${id}`).toPromise());\n  }\n\n\n}\n```\n\n### Component\n\n```typescript\nimport { Component } from '@angular/core';\nimport { AppService } from './app.service';\nimport { Post } from './post';\nimport { AsyncEventObservable } from 'rx-async-event';\n\n@Component({\n  selector: 'app-root',\n  templateUrl: './app.component.html',\n  styleUrls: ['./app.component.css'],\n  providers: [ AppService ]\n})\nexport class AppComponent {\n\n  postEvent$: AsyncEventObservable\u003cnumber, Post\u003e;\n\n  constructor(private appService: AppService) {\n    this.postEvent$ = this.appService.postEvent$;\n  }\n\n  loadPost(id: number) {\n    this.appService.loadPost(id);\n  }\n}\n```\n\n### View\n\n```html\n\u003casync-event [asyncEvent]=\"postEvent$ | async\"\u003e\n\n  \u003cdiv *asyncEventProcessing=\"let postId=argument\"\u003e\n    Processing post id {{ postId }}...\n  \u003c/div\u003e\n\n  \u003cdiv *asyncEventProcessed=\"let post=result\"\u003e\n    Post title: {{ post.title }}\n  \u003c/div\u003e\n\n\u003c/async-event\u003e\n```\n\n## Default templates\n\nIt is also possible to define default templates that will be used if no local template is defined.\n\nIn the `app.component.html` file, define them using `\u003casync-event-defaults\u003e`:\n\n```html\n\u003casync-event-defaults\u003e\n  \u003cdiv *asyncEventProcessing\u003e\n    \u003cimg src=\"spinner.gif\"\u003e\n  \u003c/div\u003e\n\n  \u003cdiv *asyncEventProcessed=\"let result=result\"\u003e\n    {{ result }}\n  \u003c/div\u003e\n\n  \u003cdiv *asyncEventError=\"let error=error\"\u003e\n    {{ error }}\n  \u003c/div\u003e\n\u003c/async-event-defaults\u003e\n```\n\nand then later:\n\n```html\n\u003casync-event [asyncEvent]=\"postEvent$ | async\"\u003e\n  \u003c!-- Default templates will be used  --\u003e\n\u003c/async-event\u003e\n```\n\nIt is also possible to create alternate defaults set using the `setName` input:\n\n```html\n\u003casync-event-defaults setName=\"debug\"\u003e\n  \u003cdiv *asyncEventProcessing=\"let argument=argument\"\u003e\n    Loading {{ argument }}...\n  \u003c/div\u003e\n\n  \u003cdiv *asyncEventProcessed=\"let result=result\"\u003e\n    {{ result | json }}\n  \u003c/div\u003e\n\n  \u003cdiv *asyncEventError=\"let error=error\"\u003e\n    {{ error }}\n    \u003ccode *ngIf=\"error.stack\"\u003e\n      {{ error.stack }}\n    \u003c/code\u003e\n  \u003c/div\u003e\n\u003c/async-event-defaults\u003e\n```\n\nand then later reference the `setName` in `\u003casync-event\u003e`:\n\n```html\n\u003casync-event [asyncEvent]=\"postEvent$ | async\" setName=\"debug\"\u003e\n  \u003c!-- Default templates for \"debug\" will be used --\u003e\n\u003c/async-event\u003e\n```\n\n## Template context\n\nThe context is passed to templates using [Angular Microsyntax](https://angular.io/guide/structural-directives#microsyntax).\n\nPlease see [async-event-template-context.ts](src/app/modules/ng-async-event/async-event-template-context.ts) for the complete object.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjulienblin%2Fng-async-event","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjulienblin%2Fng-async-event","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjulienblin%2Fng-async-event/lists"}