Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ng2-completer

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ng2-completer

ng2 autocomplete/typeahead component

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
18K
decreased by-4.03%
Maintainers
1
Weekly downloads
 
Created
Source

ng2-completer

Auto complete component for Angular 2.

This component is based on angucomplete-alt

Click for the demo

This version is a work in progress

Installation

npm install ng2-completer --sav

Usage

You should have Http and forms provided in your app:

import { bootstrap } from '@angular/platform-browser-dynamic';
import { disableDeprecatedForms, provideForms } from '@angular/forms';

import { AppComponent, environment } from './app/';
import {HTTP_PROVIDERS} from '@angular/http';

bootstrap(AppComponent, [
  HTTP_PROVIDERS,
  disableDeprecatedForms(),
  provideForms()
]);

Add ng2-completer to your component and create a data source:

import { Component } from '@angular/core';
import {AutocompCmp, AutocompService, AutocompData, AUTOCOMP_DATA_PROVIDES} from 'ng2-completer';

@Component({
  selector: 'my-component',
  template: `<h1>Search color</h1>
            <ng2-completer [(ngModel)]="searchStr" [dataService]="dataService" [minSearchLength]="0"></ng2-completer>`,
  directives: [CompleterCmp],
  providers: [AUTOCOMPLET_DATA_PROVIDES, CompleterService]
})
export class MyComponent {

  private searchStr: string;
  private dataService: CompleterData;
  private searchData = [
    { color: 'red', value: '#f00' },
    { color: 'green', value: '#0f0' },
    { color: 'blue', value: '#00f' },
    { color: 'cyan', value: '#0ff' },
    { color: 'magenta', value: '#f0f' },
    { color: 'yellow', value: '#ff0' },
    { color: 'black', value: '#000' }
  ];

  constructor(private completerService: CompleterService) {
    this.dataService = completerService.local(this.searchData, 'color', 'color');
  }
}

ng2-autocomp uses rxjs stream as data sources. There are 2 ready made data sources that can be used to fetch local and remote data but it's also possible to provide a custome source that generates a stream of items.

API

ng2-completer directive

AttributeDescriptionTypeRequiredDefault
dataServiceAutocoplete list data source.CompleterDataYes
ngModelsee the angular forms API.stringYes
autoMatchAuto select an item if it is the only result and it is an exact match of the search text.booleanfalse
clearSelectedClear the input when a result is selected.booleanNofalse
disableInputIf true disable the input field.booleanNofalse
fieldTabindexSet the tabIndex of the input.numberNo
inputNamename attribute of the input element.stringNo
matchClassCSS class to apply for matching part of the title and description.stringNo
maxCharsMaximal number of characters that the user can type in the component.numberNo524288
minSearchLengthMinimal number of characters required for searching.numberNo3
overrideSuggestedIf true will ovveride suggested and set the model with the value in the input field.booleanNofalse
pauseNumber of msec. to wait before searching.numberNo250
placeholderPlaceholder text for the search field.stringNo
selectedEvent handler that is called when an item is selected.(selected: CompleterItem): voidNo
textNoResultsText displayed when the search returned no results.stringNo
textSearchingText displayed while search is active.stringNoSearching...

Loacl data

Create local data provider by calling CompleterService.local.

Parameters
NameTypeDescriptionRequired
dataany[]A JSON array with the data to use.Yes
searchFieldsstringComma separated list of fields to search on. Fields may contain dots for nested attributes.Yes
titleFieldstringName of the field to use as title for the list item.Yes
Attributes
NameTypeDescription
descriptionFieldstringName of the field to use as description for the list item.
imageFieldstringName of the field to use as image url for the list item.

Remote data

Create remote data provider by calling CompleterService.remote.

Parameters
NameTypeDescriptionRequired
urlstringBase url for the searchYes
searchFieldsstringComma separated list of fields to search on. Fields may contain dots for nested attributes.Yes
titleFieldstringName of the field to use as title for the list item.Yes
Attributes
NameTypeDescription
descriptionFieldstringName of the field to use as description for the list item.
imageFieldstringName of the field to use as image url for the list item.
urlFormater(term: string) => stringFunction that get's the searchterm and returns the search url before each search.

CSS classes

  • .completer-holder
  • .completer-input
  • .completer-dropdown-holder
  • .completer-dropdown
  • .completer-searching
  • .completer-no-results
  • .completer-row
  • .completer-row
  • .completer-image-holder
  • .completer-image-holder
  • .completer-image
  • .completer-image-default
  • .completer-image-default
  • .completer-title
  • .completer-description
  • .completer-description
  • .completer-list-item-holder
  • .completer-list-item

Keywords

FAQs

Package last updated on 19 Jul 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc