0

I'm trying to use typeahead.js but all I'm getting is Uncaught TypeError: undefined is not a function.

I'm:

  • Loading it after jQuery
  • Not using $(document).ready(...) anywhere in my scripts
  • Using Angular JS (even I don't think it's an issue)
  • Loading jQuery after whole angular stuff
  • Made sure all scripts exist and are being loaded.

This is what my whole resources loading looks like (with out typeahead load):

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="http://bootswatch.com/flatly/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.3/animate.min.css">
<link rel="stylesheet" type="text/css" href="css/rules.css">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.3.1/lodash.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular-route.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular-cookies.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular-animate.min.js"></script>
<script type="text/javascript" src="js/angular/dependencies/checklist-model.js"></script>

<script type="text/javascript" src="js/jQuery/jquery.js"></script>  THIS NOT ANOTHER jQuery
<script type="text/javascript" src="js/functions.js"></script>

Important:

<script type="text/javascript" src="js/jQuery/jquery.js"></script> is NOT another jQuery, it's just a function which does some selections.

What I've tried for loading (after all those sripts):

  • Loading the bundle:

    <script type="text/javascript" src="js/dependencies/typeahead.bundle.min.js"></script>

  • Loading both typeahead and bloodhound:

<script type="text/javascript" src="js/dependencies/typeahead.jquery.min.js"></script> <script type="text/javascript" src="js/dependencies/bloodhound.min.js"></script>

None of these worked, I looked for any issues on github but didn't find ... This is what I'm getting, and just in case, I'm using last version of Chrome.

Update | Found the issue

I found out what's causing it, but I can't fingure out or understand why and how to fix it.

So, jQuery/jquery.js, which is NOT another jQuery is the file making it all fail and looks exactly like this:

function dojQuery () {

  $(".hover-resize").hover(

    function() { $(this).css("font-size","95px"); },
    function() { $(this).css("font-size","75px"); }
  );

  $('.dropdown-toggle').click(function() {
      var location = $(this).attr('href');
      window.location.href = location;
      return false;
  });

  $('#modifyItemModal').on('hidden.bs.modal', function () {
    $("#myOrderReview").modal('show');
  });

  $('#reviewConfirmationModal').on('hidden.bs.modal',function() {
    $("#orderReview").modal('show');
  });

  $('.supervisorModal').on('hidden.bs.modal',function() {
    $("#orderReview").modal('show');
  });

};

And the function declared is being called one within an Angular controller by simple invoking dojQuery(); Not including the fie invoking the function makes it all work good for tyepeahead.... Finally I guess it's about the jquery conflict stuff but I can't understand the fix.

9
  • 1
    Two jQuery libraries loaded? Commented Apr 11, 2015 at 5:00
  • @diegoaguilar I don't think this is a dependency issue. I think it is a no JQuery no conflict issue because you are loading JQuery then AngularJS, then some other version of JQuery. Google JQuery no conflict. Commented Apr 11, 2015 at 5:01
  • Unrelated, but as far as I remember, Bootswatch already bundles Bootstrap 3. So remove the <link> that points to bootstrap. Commented Apr 11, 2015 at 5:02
  • @JosephtheDreamer and check my edit, I'm not loading jquery twice. Commented Apr 11, 2015 at 5:03
  • Can you open the console and refresh your page. Then post the stack trace here. Commented Apr 11, 2015 at 5:06

0

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.