I'm using Algolia to build a search function. The function successfully retrieves the wanted data, but I'm struggling to read it into an array. Consider the function:
searchQ() {
this.loading = true ;
this.index.search({
query: this.searchQuery
},
async function searchDone(err, content) {
if (err) throw err;
this.SearchResults = content.hits ;
console.log(this.SearchResults) ;
console.log('hello2');
this.loading = false ;
}
);
this.searchActive = true ;
console.log(this.SearchResults) ;
console.log('hello1');
this.changeRef.detectChanges();
}
See the attached image of the console output.
On a second run of the search function, the same output is shown. The array associated with 'hello1' never takes on any values outside the searchDone function.
Search results declared here:
export class Tab2Page {
public SearchResults = [] ;
...
constructor(...) {
}
}