AngularJS - Ng-repeat - Select2 JS - Issue setting default value

1,426 views
Skip to first unread message

Jay

unread,
Jun 6, 2014, 1:29:12 PM6/6/14
to ang...@googlegroups.com
Having trouble in setting up the default value for the drop down when AngularJS/ng-repeat/custom directive + Select2 JS is used.

1. I avoided using ng-options as the directive priority is 0.
2. I tried setting the priority for the custom directive 'select2Directive' to a number less than 1000, but still no luck.

Plunker @ http://plnkr.co/edit/Csy5FqDSQbErTm2fNPac. Appreciate any help. Thanks.

Message has been deleted

Stephen Friedrich

unread,
Jun 12, 2014, 3:16:16 AM6/12/14
to ang...@googlegroups.com
Why do you use the "raw" select2 jQuery plugin?
There is an angular wrapper for it in angular-ui: https://github.com/angular-ui/ui-select2
It takes care of exactly that problem: Syncing angular mechanisms and the jQuery based select2 code.

The angular way would be not to pass the default value to your directive, but to init the model to the default value, watch the "ngModel" and set the value to the jQuery plugin whenever it changes.
Also you would have to watch the collection used in "ng-repeat" and also update the value when it changes.
This is exactly what angular-ui-select2 does.

Lee Li

unread,
Oct 11, 2014, 7:22:11 AM10/11/14
to ang...@googlegroups.com
Hi Jay,

I meet the same issue.At last, you resolve your issue? I also don't using the ui-select2. 

在 2014年6月7日星期六UTC+8上午1时29分12秒,Jay写道:
Reply all
Reply to author
Forward
0 new messages