Skip to content

Commit 339692e

Browse files
committed
Merge pull request mgcrea#290 from uxmaster/master
fix(select): issue mgcrea#245 fix, pull request mgcrea#267 bugfix
2 parents 086f2f7 + 15f353a commit 339692e

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/directives/select.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
angular.module('$strap.directives')
44

5-
.directive('bsSelect', function($timeout) {
5+
.directive('bsSelect', function($timeout, $parse) {
66

77
var NG_OPTIONS_REGEXP = /^\s*(.*?)(?:\s+as\s+(.*?))?(?:\s+group\s+by\s+(.*))?\s+for\s+(?:([\$\w][\$\w\d]*)|(?:\(\s*([\$\w][\$\w\d]*)\s*,\s*([\$\w][\$\w\d]*)\s*\)))\s+in\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

Comments
 (0)