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;
24 singleSelection : false,
28 options : MultiSelectItem[];
32 async ngOnChanges(changes: SimpleChanges) {
33 if(this.data.options$){
34 this._multiselectFormControlService.convertOriginalItems(this.data).then((options)=>{
35 this.options = options;
36 this._multiselectFormControlService.convertSelectedItems(this.data).then((res)=> {
37 this.selectedItems = res;
38 this.data.onChange(this.selectedItems ,this.form);
42 if (changes["data"] !== undefined && changes["data"].currentValue !== changes["data"].previousValue && changes["data"].firstChange) {
43 if (this.data.onInit) {
44 this.dropdownSettings.limitSelection = this.data.limitSelection;
45 this.data.onInit(this.data, this.form);
50 onItemSelect(item:any){
51 this.data.onChange(this.selectedItems ,this.form);
53 OnItemDeSelect(item:any){
54 this.data.onChange(this.selectedItems ,this.form);
56 onSelectAll(items: any){
57 this.data.onChange(this.selectedItems ,this.form);
59 onDeSelectAll(items: any){
60 this.data.onChange(this.selectedItems ,this.form);