GithubHelp home page GithubHelp logo

7silvan / ng2-input-autocomplete Goto Github PK

View Code? Open in Web Editor NEW

This project forked from liuy97/ng2-input-autocomplete

1.0 2.0 0.0 4.16 MB

angular2 input autocomplete

Home Page: https://liuy97.github.io/ng2-input-autocomplete/

License: MIT License

JavaScript 14.47% TypeScript 81.78% HTML 3.02% CSS 0.73%

ng2-input-autocomplete's Introduction

ng2-input-autocomplete

npm version Angular Style Guide Build Status

Quick links

StackBlitz Template

Angular2 input autocomplete

Installation

To install this library, run:

$ npm install ng2-input-autocomplete --save

Usage

and then from your Angular AppModule:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';

// Import your library
import { AutocompleteModule } from 'ng2-input-autocomplete';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AutocompleteModule.forRoot()
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Once your library is imported, you can use its components and directives:

Three input elements: config, items, ngModel

config supports two properties: placeholder and sourceField which is used to search. Two optional properties: class for customized css style and max for the max number of items.

Two output events: selectEvent (when a item is selected) and inputChangedEvent (when users input)

<!-- You can now use your library component in app.component.html -->
<h1>
  String
</h1>
<input autocomplete [items]=["a", "ab"]></input>
  <h2>Objects:</h2>
  <div>
    <input autocomplete [config]="config2" [items]="items2"
      (inputChangedEvent)="onInputChangedEvent($event)"
      (selectEvent)="onSelect($event)">
  </div>
  <h2>Wiki:</h2>
  <div>
    <input autocomplete [items]="wikiItems"
      (inputChangedEvent)="search($event)"
      (selectEvent)="onSelect($event)">
  </div>

in styles.css

.test li.active {
  width: 100%;
  background-color: red!important;
}

.test li {
  color: blue;
}
export class AppComponent  {
  selectedItem: any = '';
  inputChanged: any = '';
  wikiItems: any[] = [];
  items2: any[] = [{id: 0, payload: {label: 'Tom'}},
    {id: 1, payload: {label: 'John'}},
    {id: 2, payload: {label: 'Lisa'}},
    {id: 3, payload: {label: 'Js'}},
    {id: 4, payload: {label: 'Java'}},
    {id: 5, payload: {label: 'c'}},
    {id: 6, payload: {label: 'vc'}}
  ];
  config2: any = {'class': 'test', 'max': 2, 'placeholder': 'test', 'sourceField': ['payload', 'label']};

  constructor(private service: WikipediaService) {}

  onSelect(item: any) {
    this.selectedItem = item;
  }

  onInputChangedEvent(val: string) {
    this.inputChanged = val;
  }

  search (term: string) {
    this.service.search(term).subscribe(e => this.wikiItems = e, error => console.log(error));
  }
}

Development

$ npm run test

License

MIT © liuy97

ng2-input-autocomplete's People

Contributors

liuy97 avatar

Stargazers

Roman Gural avatar

Watchers

James Cloos avatar Roman Gural avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.