Closed lazaro3487 closed 7 years ago
@lazaro3487 If I understood you correctly, you need to preselect some values. To do this, you can use ngModel
or formControlName
. You should pass it an array of values. These values correspond to the valueField
of your objects(for example IDs).
For example, if you have your permissions object like this:
{ name: 'Permission 1', id: 1 }
, you should pass an array of IDs to the ngModel
or formControlName
Thanks for your response but that does not works.
the component is created like this, but when userGroup.permissions has some default values the component does not shows that.
The userGroup var is loaded inside ngOnInit of my component when a want to edit the object, any help???
<ng2-dual-list-box id="permission" name="permission" [data]="permissions" valueField="id" textField="name" [(ngModel)]="userGroup.permissions"
Regards.
@lazaro3487 Ok, since I don't know how your data looks I'm going to guess. Since your permissions array consist of objects with an id
and name property
I suppose your userGroup.permissions
has the same structure. You should do something like this.
selectedPermissions: string[] = userGroup.permissions((permission: { id: string, name: string }) => permission.id);
and then in the template:
<ng2-dual-list-box id="permission" name="permission" [data]="permissions"
valueField="id"
textField="name"
[(ngModel)]="selectedPermissions"
#permission="ngModel" required>
Basically, the ngModel
has to be a one dimensional array of values.
Closed due to no answer.
First, thanks for that component.
Is there any way for showing defaults values present in the model variable?
I need to edit the permissions of one user. How that component shows the current permissions of that user for droping or append permissions?
Regards.