algolia / angular-instantsearch

⚡️Lightning-fast search for Angular apps, by Algolia
https://algolia.com/doc/deprecated/instantsearch/angular/v4/api-reference/instantsearch/
MIT License
261 stars 73 forks source link

callback when state.refine is defined #735

Open StErMi opened 4 years ago

StErMi commented 4 years ago

Hi all,

I'm creating a custom widget that extends connectSearchBox behavior. My component has a default query value and I would like to trigger a state.refine as soon as the method is available (It seems that state.refine is initialized asynchronously).

Could you please share an example to do that? it seems that the documentation is missing for this scenario.

Haroenv commented 4 years ago

If you statically want to set a query, I think configure might suit you better. Can you explain why you want to refine as soon as it's available?

StErMi commented 4 years ago

Hi in this specific case is when a user lands directly on the search page with a predefined query like www.algolia.com/search?quert=cookbook

Haroenv commented 4 years ago

We have the "routing" feature for that: https://www.algolia.com/doc/guides/building-search-ui/going-further/routing-urls/angular/

StErMi commented 4 years ago

@Haroenv what if my case is more complex? My search route is /site/search and I've defined my algoliaConfig into layout.component.ts (where the search box is) bu results are displayed in search.component.ts.

Is it possible to still do that?

Haroenv commented 4 years ago

Yes, that should not be an issue, as long as you have an ais-instant-search

StErMi commented 4 years ago

Yes, that should not be an issue, as long as you have an ais-instant-search

what if I'm using a custom angular widget that uses connectSearchBox?

StErMi commented 4 years ago

I've tried to set up a more complex example (compared to the documentation) but it seems to not work for me. Could you provide some?

Haroenv commented 4 years ago

Can you show a non-working example please?

StErMi commented 4 years ago

Can you show a non-working example please?

Hi @Haroenv you can replicate the problem directly from the CodeSandbox that you are referring in the route documentation.

You just need to update Algolia libraries to these versions (those versions are installed by default when you create a new algolia project)

"instantsearch.css": "^7.4.2",
"instantsearch.js": "^4.7.0",
"angular-instantsearch": "^3.0.0-beta.5",
"algoliasearch": "^3.35.1"

Could you please give it a try and fix it? Because the actual example, with the newest Algolia libraries, is not working at all.

Haroenv commented 4 years ago

InstantSearch.js needs to be version 3 for Angular InstantSearch version 3, sorry if those peer dependencies aren't clear

StErMi commented 4 years ago

@Haroenv so the official documentation on algolia about angular-instasearch is wrong?

These are the dependencies suggested to install:

npm install algoliasearch@3 angular-instantsearch@beta instantsearch.js
npm install --save-dev @types/algoliasearch
Haroenv commented 4 years ago

Ah thanks for mentioning that, normally you should have gotten a peer dependency error, but the docs indeed wasn't correct. I've opened a PR to fix that