22
33angular . module ( '$strap.directives' )
44
5- . directive ( 'bsSelect' , function ( $timeout ) {
5+ . directive ( 'bsSelect' , function ( $timeout , $parse ) {
66
77 var NG_OPTIONS_REGEXP = / ^ \s * ( .* ?) (?: \s + a s \s + ( .* ?) ) ? (?: \s + g r o u p \s + b y \s + ( .* ) ) ? \s + f o r \s + (?: ( [ \$ \w ] [ \$ \w \d ] * ) | (?: \( \s * ( [ \$ \w ] [ \$ \w \d ] * ) \s * , \s * ( [ \$ \w ] [ \$ \w \d ] * ) \s * \) ) ) \s + i n \s + ( .* ) $ / ;
88
@@ -16,6 +16,7 @@ angular.module('$strap.directives')
1616
1717 $timeout ( function ( ) {
1818 element . selectpicker ( options ) ;
19+ element . unbind ( 'DOMNodeInserted DOMNodeRemoved' ) ; // disable listening for DOM updates
1920 selectpicker = element . next ( '.bootstrap-select' ) ;
2021 selectpicker . removeClass ( 'ng-scope' ) ;
2122 } ) ;
@@ -52,21 +53,17 @@ angular.module('$strap.directives')
5253 } ) ;
5354
5455 // Watch for changes to the model value
55- scope . $watch ( attrs . ngModel , function ( newValue , oldValue ) {
56- refresh ( newValue , oldValue ) ;
57- } ) ;
56+ scope . $watch ( attrs . ngModel , refresh ) ;
5857
5958 // Watch for changes to the options
6059 if ( attrs . ngOptions ) {
61- var match = attrs . ngOptions . match ( NG_OPTIONS_REGEXP ) ;
62- if ( match && scope [ match [ 7 ] ] ) {
60+ var match = attrs . ngOptions . match ( NG_OPTIONS_REGEXP ) ,
61+ valuesFn = $parse ( match [ 7 ] ) ;
62+
63+ if ( match && match [ 7 ] ) {
6364 scope . $watch ( function ( ) {
64- return scope [ match [ 7 ] ] ;
65- } , function ( newValue , oldValue ) {
66- if ( ! angular . equals ( newValue , oldValue ) ) {
67- refresh ( newValue , oldValue ) ;
68- }
69- } , true ) ;
65+ return valuesFn ( scope ) ;
66+ } , refresh , true ) ;
7067 }
7168 }
7269
0 commit comments