wardbell / ngx-subscribe

Angular directive to subscribe to observables

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NgxSubscribe

This project derives from Natanel Basel's excellent article, "DIY Subscription Handling Directive in Angular".

The code is based on his ngsubscribe-full version, downloaded from StackBlitz on 9 Feb 2019.

This version differs in that

  • using ngx prefix instead of ng, which is reserved by Angular itself

  • corrects the bug that caused the `*ngSubscribe="someObject"' variant to fail and extends that variant to support non-observable properties.

  • handles the single observable variant (`*ngSubscribe="someObservable as foo"').

  • handles null/missing observable

  • Less frequent need to check if the subscribed variable is null/undefined.

What matters

Everything and the only thing of real interest is in the ngx-subscribe.directive.ts. The rest is just the demo program that demonstrates it.

Development server

Run ng serve for a dev server. Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.

Build

Run ng build to build the project. The build artifacts will be stored in the dist/ directory. Use the -prod flag for a production build.

About

Angular directive to subscribe to observables


Languages

Language:TypeScript 76.3%Language:HTML 13.1%Language:JavaScript 9.9%Language:CSS 0.8%