11/*!
2- * ng-bootstrap-select v0.4 .0
2+ * ng-bootstrap-select v0.5 .0
33 *
44 * Licensed under MIT
55 */
@@ -89,7 +89,8 @@ function selectpickerDirective($parse, $timeout) {
8989 restrict : 'A' ,
9090 priority : 1000 ,
9191 link : function ( scope , element , attrs ) {
92- var $async = scope . $applyAsync ? '$applyAsync' : '$evalAsync' ; // fall back to $evalAsync if using AngularJS v1.2.x
92+ var $async = scope . $applyAsync ? '$applyAsync' : '$evalAsync' , // fall back to $evalAsync if using AngularJS v1.2.x
93+ selectCollection ;
9394
9495 if ( attrs . ngOptions ) {
9596 var multiple = attrs . multiple ,
@@ -100,7 +101,7 @@ function selectpickerDirective($parse, $timeout) {
100101 match = optionsExp . match ( NG_OPTIONS_REGEXP ) ;
101102
102103 // The collection to watch
103- var collection = match [ 8 ] ;
104+ selectCollection = match [ 8 ] ;
104105 // The variable name for the value of the item in the collection
105106 var valueName = match [ 5 ] || match [ 7 ] ;
106107 // The variable name for the key of the item in the collection
@@ -129,7 +130,7 @@ function selectpickerDirective($parse, $timeout) {
129130 var displayFn = $parse ( match [ 2 ] || match [ 1 ] ) ;
130131 var groupByFn = $parse ( match [ 3 ] || '' ) ;
131132 var disableWhenFn = $parse ( match [ 4 ] || '' ) ;
132- var valuesFn = $parse ( collection ) ;
133+ var valuesFn = $parse ( selectCollection ) ;
133134
134135 var locals = { } ;
135136 var getLocals = keyName ? function ( value , key ) {
@@ -140,18 +141,22 @@ function selectpickerDirective($parse, $timeout) {
140141 locals [ valueName ] = value ;
141142 return locals ;
142143 } ;
143-
144- scope . $watch ( collection , refresh , true ) ;
145144
146145 scope [ $async ] ( function ( ) {
147146 element . selectpicker ( $parse ( attrs . selectpicker ) ( ) ) ;
148147 } ) ;
149148 } else {
149+ selectCollection = attrs . selectCollection ;
150+
151+ element . selectpicker ( $parse ( attrs . selectpicker ) ( ) ) ;
152+
150153 $timeout ( function ( ) { // fall back to $timeout for selects that don't use ng-options
151- element . selectpicker ( $parse ( attrs . selectpicker ) ( ) ) ;
154+ refresh ( ) ;
152155 } ) ;
153156 }
154157
158+ if ( selectCollection ) scope . $watch ( selectCollection , refresh , true ) ;
159+
155160 function bindData ( text ) {
156161 var startIndex ,
157162 endIndex ,
0 commit comments