### File

`projects/commons/src/lib/core/field/abstract/field.ts`

### Implements

`OnInit`

### Index

###### Properties
Public form
###### Methods
Protected addFormValidator Public ngOnInit

### Constructor

`constructor(viewContainerRef: ViewContainerRef)`
Defined in projects/commons/src/lib/core/field/abstract/field.ts:5
Parameters :
Name | Type | Optional
viewContainerRef | `ViewContainerRef` | No

### Properties

Public form
Type : `FormGroup`
Defined in projects/commons/src/lib/core/field/abstract/field.ts:5

### Methods

Protected addFormValidator
`addFormValidator(name: string, validators: Validators, value: string)`
Defined in projects/commons/src/lib/core/field/abstract/field.ts:17
Parameters :
Name | Type | Optional | Default value
name | `string` | No |
validators | `Validators` | No |
value | `string` | No | `''`
Returns : `void`

Public ngOnInit
`ngOnInit()`
Defined in projects/commons/src/lib/core/field/abstract/field.ts:9
Returns : `void`

    import { OnInit, ViewContainerRef } from '@angular/core';
    import { FormControl, FormGroup, Validators } from '@angular/forms';

    export abstract class Field implements OnInit {
        public form: FormGroup;

        constructor(private readonly viewContainerRef: ViewContainerRef) {}

        public ngOnInit(): void {
            for (const element of (this.viewContainerRef.parentInjector as any).view.oldValues) {
                if (element instanceof FormGroup) {
                    this.form = element;
                }
            }
        }

        protected addFormValidator(name: string, validators: Validators, value: string = '') {
            this.form.addControl(name, new FormControl(value, validators));
        }
    }

# result-matching ""

# No results matching ""