I've been trying to get typeahead running in Aurelia for a bit today. So far I've got bloodhound to do its thing, but no luck with typeahead so far?
install steps
npm
npm install jquery --save
npm install typeahead-js --save
npm install typeahead.js-bootstrap4-css --save
typescript files*
typings install dt~jquery --global --save
typings install dt~typeahead --global --save
* side note: removed all protractor ts files to sidestep the jquery / protractor $ conflict.
added these to aurelia.json vendor bundle
"jquery",
{
"name" : "typeaheadjs",
"path" : "../node_modules/typeahead.js/dist",
"main" : "typeahead.jquery",
"deps" : ["jquery"],
"exports": "$"
},
{
"name" : "bloodhound",
"path" : "../node_modules/typeahead.js/dist",
"main" : "bloodhound"
}
make a sample element
import * as Bloodhound from 'bloodhound';
import * as $ from 'jquery';
import 'typeaheadjs';
export class Autocomplete{
activate(){
debugger;
var engine = this.makeEngine();
this.runTypeahead( engine );
}
runTypeahead( engine : any ) : void{
$( "#thetypeahead" )
.typeahead(null,
{
name: 'files',
source: engine,
limit: 20
});
}
makeEngine() : any {
var engine = new Bloodhound({
queryTokenizer: Bloodhound.tokenizers.whitespace,
datumTokenizer: Bloodhound.tokenizers.whitespace,
local: [{ id: 1, name: 'dog' }, { id: 2, name: 'pig' }],
identify: function(obj) { return obj.id; }
});
return engine;
}
}
The error message is a runtime error cause its not putting typeahead onto jquery
Message: $(...).typeahead is not a function
How to I get the typeahead plugin to load?