Skip to content

Commit d162d28

Browse files
committed
fix(selectpicker) changed styles to theme attr
1 parent 5607d91 commit d162d28

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

demo/index.html

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,13 @@ <h3>Works with ngRepeat</h3>
118118
<section id="simple-usage" ng-controller="StyleCtrl" dropdown-toggle>
119119
<h1>Style usage</h1>
120120
<div>
121-
<h3>You can set different Bootstrap classes via the data-style attribute</h3>
122-
<select selectpicker="" data-style="btn-{{color}}" ng-model="color">
123-
<option value="primary">primary</option>
124-
<option value="info">info</option>
125-
<option value="success">success</option>
121+
<h3>Works with data-style</h3>
122+
<p>You can set different Bootstrap classes via the data-style attribute</p>
123+
<select selectpicker="" sp-theme="btn-{{color}}" ng-model="color">
124+
<option value="primary">btn-primary</option>
125+
<option value="info">btn-info</option>
126+
<option value="success">btn-success</option>
127+
<option value="danger">btn-danger</option>
126128
</select>
127129
</div>
128130
</section>

src/angular-bootstrap-select.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ angular.module('angular-bootstrap-select', [])
177177
function selectpickerDirective($parse) {
178178
return {
179179
restrict: 'A',
180+
priority: 1000,
180181
link: function (scope, element, attrs) {
181182
function refresh(newVal) {
182183
scope.$applyAsync(function () {
@@ -185,10 +186,14 @@ function selectpickerDirective($parse) {
185186
});
186187
}
187188

188-
attrs.$observe('style', function (val) {
189-
console.log(val)
190-
element.selectpicker('setStyle', val);
191-
})
189+
attrs.$observe('spTheme', function (val) {
190+
scope.$applyAsync(function () {
191+
element.data('selectpicker').$button.removeClass(function (i, c) {
192+
return (c.match(/(^|\s)?btn-\S+/g) || []).join(' ');
193+
});
194+
element.selectpicker('setStyle', val);
195+
});
196+
});
192197

193198
element.selectpicker($parse(attrs.selectpicker)());
194199
element.selectpicker('refresh');

0 commit comments

Comments
 (0)