Angular 4 resetting form after update - keeping ngModel values (using ngForm) -


i feel should simple can't find (at least without lot of overhead coding) particular use case. have update profile page not modal. once user updates, want form reset original state , current values, in case user wants more edits.

i'm using ngform's reset() (also tried resetform()). resets pristine, etc., removes of values in inputs. on each of inputs i'm using [(ngmodel)]="userrecord.phone", etc. userrecord still correct.

is there simple way keep or model values after reset?

onsubmit(event, profileform: ngform) {   event.preventdefault();    const mytempvar = this.userrecord;   this.userrecord.put()     .catch((e) => {       this.isprocessing = false;       return observable.of(false);     })     .subscribe((response) => {       this.displayconfirmation = 'profile has been updated successfully.'       this.isprocessing = false;       this.userrecord = mytempvar;     }, (err) => {       console.log('there error saving', err);       this.displayerror = 'unknown error.  please refresh page , try again.'       this.isprocessing = false;     }); } 

if helps visualize, here original screen before submitting: original

here after submitting, if ngform reset(): with reset

here if don't reset. hoping this, except pristine , submit button enabled again (although i'm noticing that's not happening if reset, anyways. :-( ). without reset

before form submit clone form data tmp object:

tmpformdata: sometype = object.assign({}, currentdata); 

then after reset() can yourform.patchvalue(valuesfromtmpformdateobject)


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -