这是我的解决方案。希望有人能帮助这个。
使用以下命令安装typehead.js类型定义。
npm install --save @types/typeahead
将以下文件也添加到angular-cli.json文件中。
"assets/js/bloodhound.min.js",
"assets/js/typeahead.bundle.min.js"
不要在OnInit的下列()我已经安装了jQuery的太组件
const suggestions = [{
value: 'string1'
}, {
value: 'string2'
}, {
value: 'string3'
}, {
value: 'string4'
}, {
value: 'string5'
}];
let bloodhoundSuggestions = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
sufficient: 3,
local: this.suggestions
});
$('#tagsInput .typeahead').typeahead({
hint: true,
highlight: true,
minLength: 1
}, {
name: 'suggestions',
displayKey: 'value',
source: bloodhoundSuggestions
});
的方法。
请务必添加下列app.component.ts
import * as $ from 'jquery';
,并确保导入以下你的组件文件。
declare const Bloodhound;
declare const $;
组件的HTML文件
<div id="tagsInput">
<input class="typeahead" type="text" placeholder="States of USA">
</div>
你有没有发现这方面的任何解决方案 –