в app.module.ts import {RxReactiveFormsModule} из "@ rxweb / реактивной формы-валидаторы"
импорт: [...., RxReactiveFormsModule]
в app.component.ts
import { Component, OnInit } from '@angular/core';
import {FormGroup,FormControl,Validators } from "@angular/forms"
import {RxFormBuilder,FormGroupExtension } from "@rxweb/reactive-form-validators"
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent implements OnInit {
name = 'Angular';
editForm:FormGroup;
constructor(private formBuilder:RxFormBuilder){}
ngOnInit(){
this.editForm = this.formBuilder.group({
id:[1, Validators.required],
name: ["Anil", [
Validators.required,
Validators.pattern(
/^[A-Za-z]{1,16}([ ]?[a-zA-Z]{0,16})([ ]?[a-zA-Z]{0,16})$/
)
]],
designation: ["Software Engg", [
Validators.required,
Validators.pattern(
/^[A-Za-z]{1,16}([ ]?[a-zA-Z]{0,16})([ ]?[a-zA-Z]{0,16})$/
)
]]
});
}
onSubmit() {
console.log(this.editForm.value)
let isDirty = (<FormGroupExtension>this.editForm).isDirty()
}
}
в app.component.html
<div class="container">
<main class="col-12">
<h3 class="bd-title" id="content">Dirty Check Example</h3>
<br/>
<form [formGroup]="editForm" (ngSubmit)="onSubmit()" >
<div class="form-group">
<label>Id</label>
<input type="text" formControlName="id" class="form-control" />
</div>
<div class="form-group">
<label>Name</label>
<input type="text" formControlName="name" class="form-control" />
</div>
<div class="form-group">
<label>Designation</label>
<input type="text" formControlName="designation" class="form-control" />
</div>
<button [disabled]="!(editForm.valid ||!editForm['isDirty']())" class="btn btn-primary">Update</button>
</form>
</main></div>
Здесь я создал пример в stackblitz
Угловое обновление / форма редактирования - StackBlitz