fengxiang
2018-06-15 565f5b26ee306966f0b4b9447b7a8f9b04a9fe00
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
32
33
34
35
36
37
38
39
40
41
42
43
import { Component, OnInit } from '@angular/core';
import { _HttpClient } from '@delon/theme';
import { NzModalSubject } from 'ng-zorro-antd';
import { FormGroup } from '@angular/forms';
 
@Component({
  selector: 'app-sensor-unit',
  templateUrl: './sensor-unit.component.html',
})
export class SensorUnitComponent implements OnInit {
    public isSaving = false;
    public validateForm: FormGroup;
    public data: any;
    constructor(
        private subject: NzModalSubject,
        private http: _HttpClient
    ) { }
 
    ngOnInit() {
    }
    save($event, value, valid) {
        $event.preventDefault();
        if (valid) {
          for (const i in this.validateForm.controls) {
            this.validateForm.controls[ i ].disable();
          } 
          this.isSaving = true;
          Object.keys(value).forEach( (key: string) => {
                // '_'为前缀的为自定义属性
                if (!key.startsWith('_') && value[key] != null) {
                     this.data[key] = value[key];
                }
          } );
        } else {
          this.validate(); 
        }
    }
    validate() {
        for (const i in this.validateForm.controls) {
          this.validateForm.controls[ i ].markAsDirty();
        }
     }
}