fengxiang
2018-03-08 efe936a73370a55d4c3336fb9973a92fcf87efff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { FormGroup, FormArray, AbstractControl } from '@angular/forms';
import { Injectable } from '@angular/core';
 
@Injectable()
export class ToolsService {
      public static markAsDirty(controlSet: FormGroup|FormArray) {
         const controls = controlSet.controls;
         Object.values(controls).forEach(
             (control: AbstractControl) => {
                    if (control instanceof FormGroup || control instanceof FormArray) {
                        ToolsService.markAsDirty(control);
                    } else {
                          control.markAsDirty();
                    }
             }
         );
      }
      public static removePrivate(obj: object) {
            Object.keys(obj).forEach(
                 (key: string) => {
                        if (key.startsWith('_')) {
                            delete obj[key];
                        } else {
                            if (obj[key] instanceof Object) {
                                ToolsService.removePrivate(obj[key]);
                            }
                        }
                 }
                );
      }
}