Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example with API endpoint #8

Open
mhkeller opened this issue Mar 28, 2019 · 5 comments
Open

Example with API endpoint #8

mhkeller opened this issue Mar 28, 2019 · 5 comments

Comments

@mhkeller
Copy link

If you want to fetch results based on the input, where do you set the API endpoint? The demo page has this functionality but the source of the demo page is bundled and I don't see that site in a repo anywhere.

Thanks!

@elcobvg
Copy link
Owner

elcobvg commented Mar 29, 2019

You have to use the component like this:

<AutoComplete 
  name="countries" 
  items="{countries}" 
  isAsync="true" 
  on:input="asyncData(event)" 
  on:change="set({ country: event })">
</AutoComplete>

and then have a method in the parent like this:

methods: {
  asyncData () {
    fetchData(apiUrl).then(data => {
      const countries = data.map(item => {
        const { name, alpha3Code } = item
        return {
          key: name,
          value: alpha3Code
        }
      })
      this.set({ countries })
    })
  }
}

@elviskudo
Copy link

hi elco, thanks for your useful components

i tried implement this component, but i have problem like this
Directive value must be a JavaScript expression enclosed in curly braces
how can i solve that?
my svelte version is 3

thanks a lot

@elcobvg
Copy link
Owner

elcobvg commented Jun 13, 2019

Sorry, as soon as I have some time, I plan to update my Svelte components to v3.

@elviskudo
Copy link

oh thanks for your fast response and support

@sarahsalvini
Copy link

Was the Directive value must be a JavaScript expression enclosed in curly braces
ever resolved? I seem to still be getting the same error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants