angularUI ui-select2 directive not working
Asked Answered
S

1

7

I've been banging my head against the wall with this, so I've reduced it to the bare minimum:

index.html:

<html lang="en" ng-app="myApp">
    <body ng-controller="main">

        <select ui-select2>
            <option>12451</option>
            <option>23435</option>
            <option>3456</option>
        </select>

        <!-- Scripts loaded here. See the plunker -->

    </body>
</html>

app.js:

angular
    .module('myApp', ['ui'])
    .controller('main', function (){});

Here's the link to the Plunker: http://plnkr.co/edit/kXnHPzBt7apRc7EivLp8?p=preview

I think I'm doing it all right, but it just refuses to initialize the select2.

Here's the error I get:

Object [[object HTMLSelectElement]] has no method 'is'

Here's a screenshot of the error:

enter image description here

What am I doing wrong here?

Soekarno answered 18/12, 2012 at 2:32 Comment(0)
B
11

You need to load jQuery before AngularJS and apparently select2.js before Angular-ui

The following order works fine

<script src="jquery.min.js"></script>          
<script src="select2.js"></script>
<script src="angular.js"></script>  
<script src="angular-ui.js"></script>

Check the plunker: http://plnkr.co/edit/sAGfzmNdykEnqlH40gNf?p=preview


Check this other answer: Angular UI Select2 in the Bootstrap Navigation Bar

Braw answered 18/12, 2012 at 4:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.