私の解決策は次のとおりです。誰かがこれを助けることを願っています。
次のコマンドを使用してtypehead.jsタイプ定義をインストールします。
npm install --save @types/typeahead
以下のファイルもangular-cli.jsonファイルに追加してください。
"assets/js/bloodhound.min.js",
"assets/js/typeahead.bundle.min.js"
私も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
});
ののOnInit()メソッドで次の操作を実行します。
import * as $ from 'jquery';
をapp.component.tsそして、あなたのコンポーネントファイルに次のようにインポートすることを確認するために以下を追加することを確認してください。
declare const Bloodhound;
declare const $;
コンポーネントのHTMLファイル
<div id="tagsInput">
<input class="typeahead" type="text" placeholder="States of USA">
</div>
あなたは、このための任意の解決策を見つけますか –