Giter Club home page Giter Club logo

angular-auto-suggest's Introduction

Angular Auto Suggest

Angular auto suggest is a neat template less directive to make auto suggestions on search or infact anywhere easy and super simple.

Features

  1. Keyboard Based Navigation.
  2. On Click / Enter callback.
  3. Supports network requests.
  4. Auto abort previous requests on new request.

Your Html

<auto-suggest search-url="<some_url>" search-query-parameter="<query_string_key_name>" search-select-callback="<some_callback_method>">
	<form>
		<label> Boom </label>
		<input type="text" ng-model="search.query" ng-change="makeHttpRequest()"/>
	</form>
	<ul ng-if="search.status == 'completed' ">
		<li ng-repeat="item in response" auto-suggest-item="item" ng-class="{'active':$index == activeIndex}">
			{{::item.text}}
		</li>
	</ul>
	<p ng-if="search.status == 'initialized'"> Loading ... </p>
</auto-suggest>
// Inject angular.autosuggest here
angular.module('yourApp',['angular.autosuggest']);

Above directive supports 3 parameters

  1. search-url : The url to call everytime a user tries to enter something.
  2. search-query-parameter : The key name to append on network call.
    Example :- example.com?query . Here query is the parameter
  3. search-select-callback : Callback method to call after clicking search results or by pressing enter.

Finally you have the flexibility to decide form and result elements by urself, which means you can design them your way.

Form Element

  1. ng-model : Input field should have ng-model set to search.query
  2. ng-change : Input field should call makeHttpRequest() on ng-change.

Response Elements

  1. response : Response is the object which holds final result returned after http call, you can run normal ng-repeat to iterate over items.
  2. auto-suggest-item : It is directive required to treat your element as the main item inside ng-repeat loop. It is required to enable keyboard interactions and execute callback method.
  3. activeIndex : You can use activeIndex to match with ng-repeat $index in order to add styles to current active item.

States

While making http requests and display results , autoSuggest will switch it's states making easier for you to make visual changes.

  1. search.status : search.status will hold all the states in form of strings.
  2. idle : Idle is when nothing has happend.
  3. initialized : Will be set when making http request.
  4. completed : After http response, it can be error or success.

angular-auto-suggest's People

Contributors

thetutlage avatar

Watchers

 avatar  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.