2016-05-13 16 views
12
  • La forma che rappresenta lo stato entità viene modificato (giri sporco) è presentata
  • espressamente dichiarati entità è ora allineato con lo stato forma che significa che il modulo dovrebbe essere impostato come incontaminato.

Come si fa? C'era $setPristine() in ng1. Btw, sto parlando del tipo di modulo ControlGroup.Come impostare un modulo come incontaminato?

risposta

8

aggiornamento

Nel nuovo modulo forme questo è stato migliorato molto.

AbstractControl, la classe base della maggior parte delle classi di form fornisce

markAsTouched({onlySelf}?: {onlySelf?: boolean}) : void 
markAsUntouched({onlySelf}?: {onlySelf?: boolean}) : void 
markAsDirty({onlySelf}?: {onlySelf?: boolean}) : void 
markAsPristine({onlySelf}?: {onlySelf?: boolean}) : void 
markAsPending({onlySelf}?: {onlySelf?: boolean}) : void 

e diversi altri nuovi metodi

disable({onlySelf, emitEvent}?: {onlySelf?: boolean, emitEvent?: boolean}) : void 
enable({onlySelf, emitEvent}?: {onlySelf?: boolean, emitEvent?: boolean}) : void 
setValue(value: any, options?: Object) : void 
patchValue(value: any, options?: Object) : void 
reset(value?: any, options?: Object) : void 
updateValueAndValidity({onlySelf, emitEvent}?: {onlySelf?: boolean, emitEvent?: boolean}) : void // (old) 
setErrors(errors: {[key: string]: any}, {emitEvent}?: {emitEvent?: boolean}) : void 

originale

Al momento non è supportato. Vedi https://github.com/angular/angular/issues/5568 e https://github.com/angular/angular/issues/4933. La soluzione usuale è ricreare il modulo per ottenere uno originale.

+0

........... super ........... – Birowsky

0
class MyComp { 
    form = new FormGroup({ 
     first: new FormControl('Nancy'), 
     last: new FormControl('Drew') 
    }); 
} 

    reset() { 
     this.form.reset(); // will reset to null 
    // this.form.reset({first: 'Nancy', last: 'Drew'}); -- will reset to value specified 
    } 

https://github.com/angular/angular/pull/9974

questo apparirà in RC5 o poi.

Problemi correlati