123456789101112131415161718192021222324252627282930313233343536 |
- import { ChangeDetectorRef, inject } from '@angular/core';
- export class FormGenericComponent {
- constructor(formGroupDirective) {
- this.formGroupDirective = formGroupDirective;
- this.onChange = () => { };
- this.onTouched = () => { };
- this.changeDetectorRef = inject(ChangeDetectorRef);
- }
- hasErrors(formControl) {
- return (formControl && formControl.touched && !!formControl.errors);
- }
- get formControl() {
- return this.formGroupDirective && this.formGroupDirective.form.get(this.formControlName);
- }
- registerOnChange(fn) {
- this.onChange = fn;
- }
- registerOnTouched(fn) {
- this.onTouched = fn;
- }
- triggerChange(value) {
- if (value && this.formControl)
- this.formControl.markAsDirty();
- this.onChange(value);
- }
- triggerTouched() {
- this.onTouched();
- }
- triggerMarkCheck() {
- this.changeDetectorRef.markForCheck();
- }
- triggerChangeDetection() {
- this.changeDetectorRef.detectChanges();
- }
- }
|