我正在尝试将algolia即时搜索实现到我的Angular 5应用程序中,并且正在使用本教程:Angular Full Text Search With Algolia Frontend我安装了instantsearch.js
我收到错误消息: ERROR TypeError: instantsearch is not a function at SearchUiComponent.ngOnInit
我尝试将以下内容添加到import语句中:
import * as instantsearch from 'instantsearch.js';
declare var instantsearch: any;
和
import * as instantsearch from 'instantsearch.js/es'
SearchUi.component:
import { Component, OnInit } from '@angular/core';
import { environment } from '../../environments/environment';
import * as instantsearch from 'instantsearch.js'
export class SearchUiComponent implements OnInit {
search: any;
constructor() { }
ngOnInit() {
const options = environment.algolia;
this.search = instantsearch(options);
// search box widget
this.search.addWidget(
instantsearch.widgets.searchBox({
container: '#search-box',
autofocus: false,
placeholder: 'Search for actors',
poweredBy: true
})
);
this.search.start();
SearchUi.html
<div id="search-box">
<!-- SearchBox widget will appear here -->
</div>
<div id="hits">
<!-- Hits widget will appear here -->
</div>
答案 0 :(得分:2)
更改导入似乎可以解决问题:
import instantsearch from 'instantsearch.js/dist-es5-module/src/lib/main';