jquerynode.jsmean-stackmeanjstypeahead

"Typeahead is not a function" ERROR


I'm currently unable to use typeahead because of this error: enter image description here

I've included jquery and the typeahead packages:

<script src="libs/jquery/dist/jquery.js"></script>
<script src="libs/typeahead.js/dist/typeahead.bundle.js"></script>

Both managed with npm.

I'm calling typeahead as follows using the template from the twitter typeahead website:

$('#the-basics .typeahead').typeahead({
  hint: true,
  highlight: true,
  minLength: 1
},
{
  name: 'people',
  source: substringMatcher($scope.people)
});

I'm developing under a MEAN.js framework... am I forgetting to include something somewhere? None of the other posts have been able to help me.

Thanks!


Solution

  • So jquery can be picky about how you import libraries/scripts that aren't jquery. Generally you want to import jquery.js last so that functions in other files can be called when you do $(..).typeahead() for instance. Try modifying your script imports like below, that should fix the issue.

    <script src="libs/typeahead.js/dist/typeahead.bundle.js"></script>
    <script src="libs/jquery/dist/jquery.js"></script>