Ng2-select: Clear selection from function

Created on 18 Apr 2016  路  9Comments  路  Source: valor-software/ng2-select

Hi, is there a way to clear selection inside a function?, for example i need to clear my selection after a variable changes.

Most helpful comment

in terms of unselectAll, select All, there is a cleaner solution that doesn't use @ViewChild,

in your typescript,
private yourVariableName: any=[ ];
private clearDropDown( ){
this.yourVariableName = [ ];
}

This works with ng2-select-compact also.

All 9 comments

any update?

2

any update on this? I am desperately trying to do this but I have no luck

Hi,
found a solution using "component interaction":

--these go on the top
import {ViewChild } from "@angular/core";
import {SelectComponent } from 'ng2-select/ng2-select';

--these goes in your export class component
--myDivId is used like this
@ViewChild('myDivId')
private mySelectList: SelectComponent;

then in your function you call it like this:
if (this.mySelectList) {
var activeItem = this.mySelectList.activeOption;
if (activeItem) {
this.mySelectList.remove(activeItem)
}
}

this will remove the selection if youre using ng2-select in single mode. you can modify this to remove multiple items if youre using it in multiple mode.

I hope it helps.

@valorkin ,i will love to submit a PR today to take care of selectAll and unselectAll.Can I proceed?

Sure, I will be grateful :)

I will be sending it soon in the next 24hours max

@valorkin sent about 5hrs ago,kindly review the PR #648

in terms of unselectAll, select All, there is a cleaner solution that doesn't use @ViewChild,

in your typescript,
private yourVariableName: any=[ ];
private clearDropDown( ){
this.yourVariableName = [ ];
}

This works with ng2-select-compact also.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BenDevelopment picture BenDevelopment  路  5Comments

newerik picture newerik  路  5Comments

thanhngvpt picture thanhngvpt  路  5Comments

rkralston picture rkralston  路  3Comments

uzumakinaruto123 picture uzumakinaruto123  路  5Comments