angular-form-status-workaround
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

npm version

Angular form status workaround

Angular forms can sometimes be stuck pending as described in https://github.com/angular/angular/issues/13200 and https://github.com/angular/angular/issues/14542.

This RxJS operator provides a temporary workaround until this issue is fixed upstream. When the bug is fixed, this library will be deprecated.

Example usage

import { fixFormStatus } from 'angular-form-status-workaround';
 
form.statusChanges.pipe(
    fixFormStatus(form),
).subscribe(s => {
    // WILL emit when the async validators complete and not stay stuck at PENDING
});

This operator can also be used on any subclass of AbstractControl.

It is also possible to state the rate at which the status will be checked by passing the time in milliseconds as a second argument. Example: fixFormStatus(form, 100). The default rate is 250ms.

Unsubscribing

statusChanges like valueChanges returns an observable that does not complete. You must unsubscribe to avoid memory leaks and unwanted behavior. This can be achieved using takeUntil and takeWhile.

Examples

Only get notified when status is no longer pending.

this.form.statusChanges.pipe(
    fixFormStatus(this.form),
    takeWhile(status => status === 'PENDING', true),
    last(),
).subscribe(() => {
    // Emits once when status is no longer pending, then completes
});

Package Sidebar

Install

npm i angular-form-status-workaround

Weekly Downloads

27

Version

2.0.1

License

MIT

Unpacked Size

4.1 kB

Total Files

5

Last publish

Collaborators

  • -waylander-