Skip to content

Commit 217ad46

Browse files
committed
fix() changed to $timeout to support ngRepeat of ngOptions
1 parent 1315443 commit 217ad46

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

demo/index.html

+19
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,25 @@ <h3>Works with option data-content</h3>
150150
<option data-content="<span class='label label-inverse'>btn-inverse</span>" value="inverse">btn-inverse</option>
151151
</select>
152152
</div>
153+
<div>
154+
<h3>Works with option data-icon</h3>
155+
<p>TODO: interpolate</p>
156+
<select selectpicker="" ng-model="color">
157+
<option data-icon="glyphicon glyphicon-search" value="primary">btn-primary</option>
158+
<option data-icon="glyphicon glyphicon-thumbs-up" value="info">btn-info</option>
159+
<option data-icon="glyphicon glyphicon-bell" value="success">btn-success</option>
160+
<option data-icon="glyphicon glyphicon-phone" value="danger">btn-danger</option>
161+
<option data-icon="glyphicon glyphicon-globe" value="warning">btn-warning</option>
162+
<option data-icon="glyphicon glyphicon-play" value="inverse">btn-inverse</option>
163+
</select>
164+
</div>
165+
<div>
166+
<h3>Works with option data-icon and ngOptions</h3>
167+
<select selectpicker="">
168+
<option value="">Select one</option>
169+
<option ng-repeat="i in icons" value="{{i.id}}" data-icon="{{i.icon}}">{{i.title}}</option>
170+
</select>
171+
</div>
153172
</section>
154173
</div>
155174
</div>

demo/select-demo-app.js

+6
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,10 @@ angular.module('selectDemoApp', [
2121

2222
.controller('StyleCtrl', function ($scope, $timeout) {
2323
$scope.color = 'success';
24+
$scope.icons = [
25+
{ id: 0, icon: 'glyphicon glyphicon-search', title: 'Search' },
26+
{ id: 1, icon: 'glyphicon glyphicon-headphones', title: 'Headphones' },
27+
{ id: 2, icon: 'glyphicon glyphicon-ok', title: 'Ok' },
28+
{ id: 3, icon: 'glyphicon glyphicon-user', title: 'User' }
29+
];
2430
})

src/angular-bootstrap-select.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ function dropdownCloseDirective() {
143143
*/
144144

145145
angular.module('angular-bootstrap-select', [])
146-
.directive('selectpicker', ['$parse', selectpickerDirective]);
146+
.directive('selectpicker', ['$parse', '$timeout', selectpickerDirective]);
147147

148148
/**
149149
* @ngdoc directive
@@ -174,7 +174,7 @@ angular.module('angular-bootstrap-select', [])
174174
* ```
175175
*/
176176

177-
function selectpickerDirective($parse) {
177+
function selectpickerDirective($parse, $timeout) {
178178
return {
179179
restrict: 'A',
180180
priority: 1000,
@@ -187,16 +187,18 @@ function selectpickerDirective($parse) {
187187
}
188188

189189
attrs.$observe('spTheme', function (val) {
190-
scope.$applyAsync(function () {
190+
$timeout(function () {
191191
element.data('selectpicker').$button.removeClass(function (i, c) {
192192
return (c.match(/(^|\s)?btn-\S+/g) || []).join(' ');
193193
});
194194
element.selectpicker('setStyle', val);
195195
});
196196
});
197197

198-
element.selectpicker($parse(attrs.selectpicker)());
199-
element.selectpicker('refresh');
198+
$timeout(function () {
199+
element.selectpicker($parse(attrs.selectpicker)());
200+
element.selectpicker('refresh');
201+
});
200202

201203
if (attrs.ngModel) {
202204
scope.$watch(attrs.ngModel, refresh, true);
@@ -207,7 +209,7 @@ function selectpickerDirective($parse) {
207209
}
208210

209211
scope.$on('$destroy', function () {
210-
scope.$applyAsync(function () {
212+
$timeout(function () {
211213
element.selectpicker('destroy');
212214
});
213215
});

0 commit comments

Comments
 (0)