summaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/shared/components/formControls/component/dropdown/dropdown.formControl.component.ts
blob: 8148368dd10d00f2e1ec2abd1207b33bba6b876f (plain)
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
import {Component, Input, OnChanges, SimpleChanges} from "@angular/core";
import {DropdownFormControl} from "../../../../models/formControlModels/dropdownFormControl.model";
import {FormGroup} from "@angular/forms";

@Component({
  selector: 'dropdown-form-control',
  templateUrl: './dropdown.formControl.component.html',
  styleUrls : ['./dropdown.formControl.component.scss']
})
export class DropdownFormControlComponent implements OnChanges{
  @Input() data: DropdownFormControl = null;
  @Input() form: FormGroup = null;


  ngOnChanges(changes: SimpleChanges): void {
    if (changes["data"] !== undefined && changes["data"].currentValue !== changes["data"].previousValue && changes["data"].firstChange) {
      if(this.data.onInit){
        this.data.onInit(this.data, this.form);
      }
      let isRequired: boolean =this.data.isRequired();
    }

    if (changes["data"] !== undefined) {
      this.form.controls[this.data.controlName].valueChanges.subscribe((value)=>{
        this.data.onChange(value, this.form);
      })
    }
  }
}