angularUI ui-select2指令不起作用

时间:2022-09-26 11:22:15

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

我一直用这个撞在墙上,所以我把它减少到最低限度:

index.html:

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:

app.js:

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

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

以下是Plunker的链接:http://plnkr.co/edit/kXnHPzBt7apRc7EivLp8?p = preview

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

我想我做得很好,但它只是拒绝初始化select2。

Here's the error I get:

这是我得到的错误:

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

对象[[对象HTMLSelectElement]]没有方法'是'

Here's a screenshot of the error:

这是错误的屏幕截图:

angularUI ui-select2指令不起作用

What am I doing wrong here?

我在这做错了什么?

1 个解决方案

#1


11  

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

你需要在AngularJS之前加载jQuery,然后在Angular-ui之前加载select2.js

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

检查plunker:http://plnkr.co/edit/sAGfzmNdykEnqlH40gNf?p = preview


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

检查另一个答案:Bootstrap导航栏中的Angular UI Select2

#1


11  

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

你需要在AngularJS之前加载jQuery,然后在Angular-ui之前加载select2.js

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

检查plunker:http://plnkr.co/edit/sAGfzmNdykEnqlH40gNf?p = preview


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

检查另一个答案:Bootstrap导航栏中的Angular UI Select2