9

I am trying to implement http://silviomoreto.github.io/bootstrap-select/ to my AngularJS application.

Most of the people who try and do the same, they have any issue that the selectpicker is set before Angular gets the data. But for me that is not the case. When Select Picker is fired, my select has all the data but for some reason the dropdown toggle event is not firing.

HTML:

<select id="partyRole" name="partyRole" class="form-control" ng-model="partyRole" ng-options="role as role.text for role in partyRoles">
    <option value="">Please Select...</option>
</select>

The JS calls adds selectpicker to all my selects.

JS:

$(window).bind("load", function () {
    return $('select').selectpicker();
});

I am also using this directive to bind the selectpicker data:

https://github.com/joaoneto/angular-bootstrap-select/blob/master/build/angular-bootstrap-select.js

Final UI

Final UI

As you can see the div gets created from the selectpicker and I also get all the data.. But clicking on the button does nothing.

I have Angular UI, Angular JS in the application with Bootstrap stylesheets.

EDIT:

Nevermind, the version of the angular directive I downloaded from github was probably in a broken state, because after I applied it from today's updated code.. it worked.

1
  • 1
    Nevermind, the version of the angular directive I downloaded from github was probably in a broken state, because after I applied it from today's updated code.. it worked. Commented Jun 23, 2014 at 23:43

2 Answers 2

2

You don't want to have have some jQuery in a file and some AngularJS in another file, usually. If jQuery creates elements etc, they probably won't be picked up by angular.

The correct solution is to use an Angular directive. Here, it looks like somebody made one for you.

Sign up to request clarification or add additional context in comments.

5 Comments

I am not sure if you saw my post to the fullest, but I am already using that directive. If I hook this directive up without using "$(window).bind("load", function () { return $('select').selectpicker(); });" Then none of the selects get the new styles.
@ArjaaAine I know this an old thread but what did you do to fix this?
from the op: "Nevermind, the version of the angular directive I downloaded from github was probably in a broken state, because after I applied it from today's updated code.. it worked."
Thanks for the quick reply Ven. I am going to edit my main post, so it avoids future confusions
(DEPRECATED) angular-bootstrap-select... wouldn't touch that directive.
1
function Selectpicker() {
    return {
        restrict: 'C',
        link: function($scope, $element) {
            $element.selectpicker();
        }
    };
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.