I'm trying to follow this tutorial here : https://www.algolia.com/doc/tutorials/search-ui/instant-search/build-an-instant-search-results-page/instantsearchjs/
in order to implement instantsearchjs in my website.
Everything is linked Okay, i can query and have result in .JSON from my website .
But i don't understant how to render it, i can't put the fonction outside the ngOnInit()
Here is my file :
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import * as firebase from 'firebase';
import * as algoliasearch from 'algoliasearch';
import * as instantsearch from 'instantsearch.js';
@Component({
selector: 'app-homepage',
templateUrl: './homepage.component.html',
styleUrls: ['./homepage.component.css'],
})
export class HomepageComponent implements OnInit {
constructor(private router: Router) {
}
var search = instantsearch({
// Replace with your own values
appId: '4DJA9OYKC1',
apiKey: '12de76865a02a406ee95786c6f4a3cf3', // search only API key, no ADMIN key
indexName: 'events',
urlSync: true
});
search.addWidget(
instantsearch.widgets.searchBox({
container: '#search-input'
})
);
search.addWidget(
instantsearch.widgets.hits({
container: '#hits',
hitsPerPage: 10,
templates: {
item: document.getElementById('hit-template').innerHTML,
empty: "We didn't find any results for the search <em>\"{{query}}\"</em>"
}
})
);
search.addWidget(
instantsearch.widgets.pagination({
container: '#pagination'
})
);
ngOnInit() {
var client = algoliasearch('4DJA9OYKC1', '12de76865a02a406ee95786c6f4a3cf3');
var index = client.initIndex('events');
index.search('Ada', function(err, content) {
console.log(content.hits);
//console.log(err);
});
I think it's a problem of function inside the TS but i don't see how to implement it in Angular.
Inside Oninit it compile but error everywhere on the page, and outside it doesn't compile.
The code in ng on init in the example work perfectly and give me the result on the website console.
Thanks in advance for the help of the community