Skip to content
This repository has been archived by the owner on May 21, 2021. It is now read-only.

not binding initial model value #9

Closed
bruno-barros opened this issue Jul 20, 2014 · 4 comments
Closed

not binding initial model value #9

bruno-barros opened this issue Jul 20, 2014 · 4 comments
Assignees
Labels

Comments

@bruno-barros
Copy link

I'm passing a model with some IDs, but the dropdown don't initialize these values. Always starts with no selected items.

<div w11k-select ng-model="item.role_ids">
item.role_ids = [1,2,3]

How could I accomplish that?

I forked the plunker example and tried to apply a inital value: http://plnkr.co/edit/s1j20CAiOqlioeAWvo5y?p=preview
$scope.select.selection = [{ label: 1, value: 1 }, { label: 2, value: 2 }];
or
$scope.select.selection = [1,2];

@bruno-barros
Copy link
Author

Looking the code I noted that the controller.$viewValue return undefined, no matter if ng-model has some. So a included a new scope attribute on directive and now I can get the model initial value.
scope: { initModel: '=' },
Now inside updateOptions() I did var viewValue = scope.initModel || controller.$viewValue; and it works. I don't know why controller.$viewValue is returning undefined.

@pburgmer pburgmer added the bug label Jul 21, 2014
@pburgmer pburgmer self-assigned this Jul 21, 2014
@pburgmer
Copy link
Collaborator

Hi Bruno,

Thanks for the bug report and the plunker. I fixed it. The viewValue was set in applyConfig with an empty selection. I will release 0.4.6 with this fix and some performance improvements as soon as possible.

@pburgmer
Copy link
Collaborator

By the way: A workaround for 0.4.5 is to use $timeout to set the initial selection.

@bruno-barros
Copy link
Author

Yeah!!!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants