Merge from ecomp 718fd196 - Modern UI
[vid.git] / vid-webpack-master / src / app / shared / components / formControls / component / dropdown / dropdown.formControl.component.ts
1 import {Component, Input, OnChanges, SimpleChanges} from "@angular/core";
2 import {DropdownFormControl} from "../../../../models/formControlModels/dropdownFormControl.model";
3 import {FormGroup} from "@angular/forms";
4
5 @Component({
6   selector: 'dropdown-form-control',
7   templateUrl: './dropdown.formControl.component.html',
8   styleUrls : ['./dropdown.formControl.component.scss']
9 })
10 export class DropdownFormControlComponent implements OnChanges{
11   @Input() data: DropdownFormControl = null;
12   @Input() form: FormGroup = null;
13
14
15   ngOnChanges(changes: SimpleChanges): void {
16     if (changes["data"] !== undefined && changes["data"].currentValue !== changes["data"].previousValue && changes["data"].firstChange) {
17       if(this.data.onInit){
18         this.data.onInit(this.data, this.form);
19       }
20       let isRequired: boolean =this.data.isRequired();
21     }
22
23     if (changes["data"] !== undefined) {
24       this.form.controls[this.data.controlName].valueChanges.subscribe((value)=>{
25         this.data.onChange(value, this.form);
26       })
27     }
28   }
29 }