ng-multiselect-dropdown-with-properties
Version:
Angular Multi-Select Dropdown with Properties
88 lines (76 loc) • 2.6 kB
text/typescript
import { Component, OnInit } from '@angular/core';
export class SingleDemoComponent implements OnInit {
cities: Array<string> = [];
selectedItem: Array<string> = [];
dropdownSettings: any = {};
closeDropdownSelection = false;
disabled = false;
htmlCode = `
<ng-multiselect-dropdown
name="city"
[data]="cities"
[(ngModel)]="selectedItem"
[settings]="dropdownSettings"
(onSelect)="onItemSelect($event)"
[disabled]="disabled"
</ng-multiselect-dropdown>
`;
typescriptCode = `
import { Component, OnInit } from '@angular/core';
export class SingleDemoComponent implements OnInit {
cities: Array<string> = [];
selectedItem: Array<string> = [];
dropdownSettings: any = {};
closeDropdownSelection=false;
disabled=false;
ngOnInit() {
this.cities = ['Mumbai', 'New Delhi', 'Bangaluru', 'Pune', 'Navsari'];
this.selectedItem = ['Pune'];
this.dropdownSettings = {
singleSelection: true,
selectAllText: 'Select All',
unSelectAllText: 'UnSelect All',
allowSearchFilter: true,
closeDropDownOnSelection: this.closeDropdownSelection
};
}
onItemSelect(item: any) {
console.log('onItemSelect', item);
}
toggleCloseDropdownSelection() {
this.closeDropdownSelection = !this.closeDropdownSelection;
this.dropdownSettings = Object.assign({}, this.dropdownSettings,{closeDropDownOnSelection: this.closeDropdownSelection});
}
}
`;
ngOnInit() {
this.cities = ['Mumbai', 'New Delhi', 'Bangaluru', 'Pune', 'Navsari'];
this.dropdownSettings = {
singleSelection: true,
selectAllText: 'Select All',
unSelectAllText: 'UnSelect All',
allowSearchFilter: true,
closeDropDownOnSelection: this.closeDropdownSelection
};
this.selectedItem = ['Mumbai'];
}
onItemSelect(item: any) {
console.log('onItemSelect', item);
console.log('selectedItem', this.selectedItem);
}
toggleCloseDropdownSelection() {
this.closeDropdownSelection = !this.closeDropdownSelection;
this.dropdownSettings = Object.assign({}, this.dropdownSettings, { closeDropDownOnSelection: this.closeDropdownSelection });
}
handleReset() {
this.selectedItem = [];
}
}