2016-05-13 3 views
12
  • postać, która reprezentuje stan podmiotu jest edytowany (odwraca brudna)
  • Forma jest złożone i stanu podmiotu jest teraz wyrównana ze stanem postaci, co oznacza, że ​​kształt powinien być ustawiony jako nietknięta.

Jak to robimy? W ng1 było $setPristine(). Btw, mówię o typie postaci.Jak ustawić formularz jako nieskazitelny?

Odpowiedz

8

aktualizacja

W nowym module formy to było o wiele lepsze.

AbstractControl klasa bazowa większości klas forma zapewnia

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 

i kilku innych nowych metod

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 

oryginał

To nie jest obecnie obsługiwane. Zobacz https://github.com/angular/angular/issues/5568 i https://github.com/angular/angular/issues/4933. Typowe obejście polega na ponownym utworzeniu formularza w celu uzyskania nieskazitelnego.

+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

ten pojawi się w RC5 lub później.