1 import {Component, Input, OnChanges, SimpleChanges} from "@angular/core";
2 import {FormGroup} from "@angular/forms";
3 import {MultiselectFormControl} from "../../../../models/formControlModels/multiselectFormControl.model";
4 import {MultiselectFormControlService} from "./multiselect.formControl.service";
5 import {MultiSelectItem} from "./multiselect.model";
8 selector: 'multiselect-form-control',
9 templateUrl: './multiselect.formControl.component.html'
11 export class MultiselectFormControlComponent implements OnChanges{
12 @Input() data: MultiselectFormControl = null;
13 @Input() multiselectOptions: [] = null;
14 @Input() selectedItems = [];
15 @Input() form: FormGroup = null;
18 multiselectFormControlService : MultiselectFormControlService;
19 constructor(private _multiselectFormControlService : MultiselectFormControlService){
20 this.multiselectFormControlService = _multiselectFormControlService;
23 singleSelection : false
26 options : MultiSelectItem[];
30 async ngOnChanges(changes: SimpleChanges) {
31 if(this.data.options$){
32 this._multiselectFormControlService.convertOriginalItems(this.data).then((options)=>{
33 this.options = options;
34 this._multiselectFormControlService.convertSelectedItems(this.data).then((res)=> {
35 this.selectedItems = res;
36 this.form.controls[this.data.controlName].setValue(this.selectedItems);
41 if (changes["data"] !== undefined && changes["data"].currentValue !== changes["data"].previousValue && changes["data"].firstChange) {
42 if (this.data.onInit) {
43 this.data.onInit(this.data, this.form);
48 onItemSelect(item:any){
49 this.data.onChange(this.selectedItems ,this.form);
51 OnItemDeSelect(item:any){
52 this.data.onChange(this.selectedItems ,this.form);
54 onSelectAll(items: any){
55 this.data.onChange(this.selectedItems ,this.form);
57 onDeSelectAll(items: any){
58 this.data.onChange(this.selectedItems ,this.form);