aleksei
aleksei

Reputation: 365

Angular 4 scheduled form autosave

I'm trying to implement form data autosave in Angular 4. It should work like this:

I suppose that Observable, Subject and Scheduler from RxJS will help me, but I am completely new to it. Could you suggest the best approach for achieving above functionality please?

Upvotes: 15

Views: 6188

Answers (2)

J K
J K

Reputation: 934

For Angular 6, you may have to use pipe.

this.form.valueChanges.pipe(auditTime(2000)).subscribe(formData => /* save to DB */)

Upvotes: 14

martin
martin

Reputation: 96899

You can just subscribe to valueChanges property on FormGroup object chained with the auditTime operator:

this.form.valueChanges.auditTime(2000).subscribe(formData => /* save to DB */)

Maybe also have a look at throttleTime and debounceTime operators.

Upvotes: 17

Related Questions