npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angular-ngx-autocomplete

v2.1.2

Published

Angular autocomplete

Downloads

177

Readme

Angular Autocomplete

angular-ngx-autocomplete is a library of Angular for implementing lookups into your angular application.

Table of contents

Features

  • [x] Flexible autocomplete with client/server filtering.
  • [x] Variable properties and event bindings.
  • [x] Selection history.
  • [x] Custom item and 'not found' templates.
  • [x] Infinite scroll.
  • [x] Compatible with Angular forms API (Both Reactive and Template-driven forms).
  • [x] Keyboard navigation.
  • [x] Accessibility.

Getting started

Step 1: Install angular-ngx-autocomplete:

NPM

npm i angular-ngx-autocomplete

Step 2: Import the AutoCompleteModule:

import {AutoCompleteModule} from 'angular-ngx-autocomplete';

@NgModule({
  declarations: [AppComponent],
  imports: [AutoCompleteModule],
  bootstrap: [AppComponent]
})
export class AppModule {}

Usage sample

<div class="ngx-autocomplete">
<ngx-autocomplete 
  [data]="data"
  [searchOnProperty]="keyword"
  (selected)='selectEvent($event)'
  (inputChanged)='onChangeSearch($event)'
  (inputFocused)='onFocused($event)'
  [itemTemplate]="itemTemplate"
  [notFoundTemplate]="notFoundTemplate">                                 
</ngx-autocomplete>

<ng-template #itemTemplate let-item>
<a [innerHTML]="item.name"></a>
</ng-template>

<ng-template #notFoundTemplate let-notFound>
<div [innerHTML]="notFound"></div>
</ng-template>
</div>

class TestComponent {
  keyword = 'name';
  data = [
     {
       id: 1,
       name: 'Usa'
     },
     {
       id: 2,
       name: 'England'
     }
  ];


  selectEvent(item) {
    // do something with selected item
  }

  onChangeSearch(val: string) {
    // fetch remote data from here
    // And reassign the 'data' which is binded to 'data' property.
  }
  
  onFocused(e){
    // do something when input is focused
  }
}

API

Inputs

| Input | Type | Default | Required | Description | | ------------- | ------------- | ------------- | ------------- | ------------- | | [data] | Array<any> | null | yes | Items array. It can be array of strings or array of objects. | | inputClass | string | - | no | Style class for input field. | | foundClass | string | - | no | Style class for suggestions box. | | notFoundClass | string | - | no | Style class for no results found box. | | isEditable | boolean | false| no | Gives ability to enter custom text if no match is found. | searchOnProperty | string | - | yes | Variable name to filter data with. | | customFilter | (items: any[], query: string) => any[] | undefined | no | Custom filter function. You can use it to provide your own filtering function, as e.g. fuzzy-matching filtering, or to disable filtering at all (just pass (items) => items as a filter). Do not change the items argument given, return filtered list instead. | | placeholder | string | - | no | HTML <input> placeholder text. | | heading | string | - | no | Heading text of items list. If it is null then heading is hidden. | | initialValue | any | _ | no | initial/default selected value. | | focusFirst | boolean | false | no | Automatically focus the first matched item on the list. | | historyIdentifier | string | _ | no | History identifier of history list. When valid history identifier is given, then component stores selected item to local storage of user's browser. If it is null then history is hidden. History list is visible if at least one history item is stored. History identifier must be unique. | | historyHeading | string | Recently selected | no | Heading text of history list. If it is null then history heading is hidden. | | historyListMaxNumber | number | 15 | no | Maximum number of items in the history list. | | noResultsText | string | No match found for <Entered Input> | no | Set custom text when filter returns empty result. | | isLoading | boolean | false | no | Set the loading state when data is being loaded. | | minQueryLength | number | 1 | no | The minimum number of characters the user must type before a search is performed. | | debounceTime | number | _ | no | Delay time while typing. | | disabled | boolean | false | no | input disable/enable. | | name | string | _ | yes (If NgModel is used within a form tag) | Tracks the name bound to the NgModel directive. For more details click here | | [(ngModel)] | any | _ | no | Tracks the value bound to this directive. Used with Template-driven forms. For more details click here | | [formControl] / formControlName | string | _ | no | Tracks the FormControl instance bound to the directive. Used with Reactive forms. For more details click here and here |

Outputs

| Output | Description | | ------------- | ------------- | | (selected) | Event is emitted when an item from the list is selected. | | (inputChanged) | Event is emitted when an input is changed. | | (inputFocused) | Event is emitted when an input is focused. | | (inputCleared) | Event is emitted when an input is cleared. | | (opened) | Event is emitted when the autocomplete panel is opened. | | (closed) | Event is emitted when the autocomplete panel is closed. | | (scrolledToEnd) | Event is emitted when scrolled to the end of items. Can be used for loading more items in chunks. |

Methods (controls)

Name | Description | | ------------- | ------------- | | open | Opens the autocomplete panel | | close | Closes the autocomplete panel | | focus | Focuses the autocomplete input element | | clear | Clears the autocomplete input element |

To access the control methods of the component you should use @ViewChild decorator. See the example below:

<ngx-autocomplete #auto></ngx-autocomplete>
class TestComponent {
  @ViewChild('auto') auto;

  openPanel(e): void {
    e.stopPropagation();
    this.auto.open();
  }
  
  closePanel(e): void {
    e.stopPropagation();
    this.auto.close();
    }
    
  focus(e): void {
    e.stopPropagation();
    this.auto.focus();
  }  
}

Styles

If you are not happy with default styles you can easily override them:

<div class="ngx-autocomplete">
<ngx-autocomplete></ngx-autocomplete>
</div>
.ngx-autocomplete {
    width: 400px;
}

Author

  • [Sam Arora]

License

MIT