未定义的角度选择错误不是一个函数

时间:2014-07-25 23:39:15

标签: javascript jquery angularjs jquery-chosen

代码:http://plnkr.co/edit/H2hmEukfjaPL1T4W298O?p=preview

HTML:

<html ng-app="plunker">

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <link data-require="chosen@*" data-semver="1.0.0" rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/chosen/1.0/chosen.min.css" />
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link rel="stylesheet" href="style.css" />
    <script data-require="angular.js@1.2.x" src="https://code.angularjs.org/1.2.20/angular.js" data-semver="1.2.20"></script>
    <script data-require="jquery@*" data-semver="2.1.1" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="chosen.jquery.js"></script>
    <script src="chosen.js"></script>
    <script src="app.js"></script>
  </head>

  <body ng-controller="MainCtrl">
    <p>Hello {{name}}!</p>

    <select chosen ng-model="bar">
      <option>Hi</option>
      <option>This is fun</option>
      <option>I like Chosen so much</option>
      <option>I also like bunny rabbits</option>
      <option value=""></option>
    </select>
  </body>

</html>

JS:

var app = angular.module('plunker', ['localytics.directives']);

我不知道为什么我会这样:

  

TypeError:undefined不是函数       在http://run.plnkr.co/lPtcBAAKhcfkB6tE/chosen.js:86:26       在https://code.angularjs.org/1.2.20/angular.js:5873:13       在范围。$ eval(https://code.angularjs.org/1.2.20/angular.js:12608:28)       在Scope。$ digest(https://code.angularjs.org/1.2.20/angular.js:12420:31)       在Scope。$ apply(https://code.angularjs.org/1.2.20/angular.js:12712:24)       在https://code.angularjs.org/1.2.20/angular.js:1419:15       at Object.invoke(https://code.angularjs.org/1.2.20/angular.js:3918:17)       at doBootstrap(https://code.angularjs.org/1.2.20/angular.js:1417:14)       在bootstrap(https://code.angularjs.org/1.2.20/angular.js:1431:12)       在angularInit(https://code.angularjs.org/1.2.20/angular.js:1344:5

有任何线索吗?

1 个答案:

答案 0 :(得分:2)

在这种情况下,你需要在angularjs之前使用jquery

<html ng-app="plunker">

  <head>
     <meta charset="utf-8" />
     <title>AngularJS Plunker</title>
     <link data-require="chosen@*" data-semver="1.0.0" rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/chosen/1.0/chosen.min.css" />
    <script>document.write('<base href="' + document.location + '" />');</script>
  <link rel="stylesheet" href="style.css" />
  <script data-require="jquery@*" data-semver="2.1.1" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>    <script data-require="angular.js@1.2.x" src="https://code.angularjs.org/1.2.20/angular.js" data-semver="1.2.20"></script>
 <script src="chosen.jquery.js"></script>
 <script src="chosen.js"></script>
 <script src="app.js"></script>
</head>
 <body ng-controller="MainCtrl">
 <p>Hello {{name}}!</p>
<select chosen ng-model="bar">
  <option>Hi</option>
  <option>This is fun</option>
  <option>I like Chosen so much</option>
  <option>I also like bunny rabbits</option>
  <option value=""></option>
</select>
</body>
</html>