import { Component, OnInit, Input } from '@angular/core'; import { NzModalRef } from 'ng-zorro-antd/modal'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { HttpClient } from '@angular/common/http'; import { MyValidators } from '../addcamera/addcamera.component'; @Component({ selector: 'app-editcamera', templateUrl: './editcamera.component.html', styleUrls: ['./editcamera.component.scss'] }) export class EditcameraComponent implements OnInit { @Input() data: any validateForm!: FormGroup; constructor(private modal: NzModalRef, private fb: FormBuilder, private http: HttpClient) { } ngOnInit(): void { const { namevalidate } = MyValidators; let datacopy = JSON.parse(JSON.stringify(this.data)) console.log('编辑数据', datacopy) this.validateForm = this.fb.group({ name: [datacopy.name, [Validators.required,namevalidate]], user: [datacopy.user, [Validators.required]], password: [datacopy.password, [Validators.required]], uri: [datacopy.uri, [Validators.required]], type: [datacopy.type, [Validators.required]], order: [datacopy.order, [Validators.required]] }); } }