summaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/shared/components/formControls/component/dropdown/dropdown.formControl.component.ts
blob: 550feca2288e24307e6eed4325dc48428edfdf98 (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
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);
      }
    }

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