sengirab / ngAutocomplete

Light-weight autocomplete component for Angular.
MIT License
52 stars 24 forks source link

Add sample code for loading data asynchronously #17

Closed josephbagnes closed 5 years ago

josephbagnes commented 6 years ago

It would be really helpful if this is included. I'm struggling to load the data asynchronously. Thanks!

theCrius commented 6 years ago

Came here for the same reason. The example written in the "new feature" isn't much clear and I'm struggling to understand which is the logic to use it.

darmie commented 6 years ago

This is how to do it =>

    let autoComp = CreateNewAutocompleteGroup(
      'Search / choose in / from list',
      'completer',
      [
        { title: 'Option 1', id: '1' },
        { title: 'Option 2', id: '2' },
        { title: 'Option 3', id: '3' },
        { title: 'Option 4', id: '4' },
        { title: 'Option 5', id: '5' },
      ],
      { titleKey: 'title', childrenKey: null }
    )

    // set async function
    autoComp.async = async (str):Promise<any> =>{
      //add new Item to drop down
      return [{ title: 'hello', id: '' }]
    }

    this.group = [
      autoComp
    ];
sengirab commented 6 years ago

Thanks. This is it yes.

josephbagnes commented 5 years ago

Thanks a lot!