matsura / ng2-dual-list-box

A dual list box component for Angular 4
http://ng2-duallistbox-demo.surge.sh/
28 stars 20 forks source link

Set values in the selected items container is not working #26

Open vidyambala opened 6 years ago

vidyambala commented 6 years ago

Set values in the selected items container is not working. Tried both ngModel and formControlName.

deiyanfott commented 6 years ago

@vidyambala

Maybe you can find an idea using the snippet below as a guide.

In the component tag <ng2-dual-list-box ...>, you can do something like <ng2-dual-list-box #test ...>.

Then plug it in some method you are using, say (click)=startTask(test, ...)

Then inside the method you can do startTask(test: DualListBoxComponent, ...) { test.selectedItems = [insert preset values here]; }

akshaydusane commented 6 years ago

I tried this but it is not working

<ng2-dual-list-box #courseList [data]="source" valueField="id" textField="name" [(ngModel)] = "selected" (onAvailableItemSelected)="listlog($event)" (onSelectedItemsSelected)="listlog($event)" (onItemsMoved)="listlog($event)">

I am passing courseList from function and in TS I wrote

this.target = [ { id: 4, name: 'qwe' }, { id: 5, name: 'qwe Horn' }, { id: 6, name: 'qwe' }, ];

  this.selected = [...this.target]

  courseList.selectedItems = this.selected
sarveshnineleaps commented 5 years ago

@akshaydusane How I can use this using ngFor for angular 5

belalothman commented 4 years ago

since there is no good answer here I edited the library and fixed the problem, if any one need My fixed version just write it here

venkateshjaicha commented 4 years ago

Hi,I want to display default values on the selected items on page load?? any idea

venkateshjaicha commented 4 years ago

since there is no good answer here I edited the library and fixed the problem, if any one need My fixed version just write it here

is there any fixed version?