• Stars
    star
    108
  • Rank 321,259 (Top 7 %)
  • Language
    JavaScript
  • Created over 10 years ago
  • Updated over 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Angular Autocompleter based on Twitter Bloodhound

ngAtp : Angular Autocompleter

Demo

http://yiransheng.github.io/ngAtp/

Credits

The backbone of ngAtp is ngBloodhound, which is almost entirely adopted from twhitbeck's angular-bloodhound, an Angular port of Twitter's Bloodhound.

Quick Start

Include dist/js/ng-atp-bundle.js or dist/js/ng-atp-bundle.min.js on your page after angular and lodash1 (or use as a bower component: bower install ng-atp).

[1] lodash is no longer a dependency

  • For CommonJS:
var _ = require('lodash');
var angular = require('angular');
require('ng-atp');  // exports angular.module('ng-atp')

Use:

Update:

Added in config options: completeOn. Default Value : { tab: true, rightArrow: true }. Can be used to fine-tune whether to autocomplete on tab or right arrow key.

<div ng-atp="city" ng-atp-config="cityAutocompleteOpts">
    <input ng-atp-input />
    <ul ng-atp-suggestions>
    </ul>
</div>

Set ng-atp attribute value to the variable in scope you'd like to autocomplete for, same way you'd use a ngModel directive. Pass Bloodhound config object using ng-atp-config attribute. Additonal config options: idAttribute, specify the key/id attribute to use for tracking suggestion items (similar to track by for ng-repeat). Also, you should to supply two functions in config: format and verify(optional). format is expected to be a function that takes a suggestion datum (eg. { label: "Thing", id: 1}) into a string to display, and verify is expected to be a function that takes a single suggestion datum as an argument, and returns a boolean (be sure to return false for null).

In addition, ng-atp-suggestions allows you to use custom template by suppling an attribute template-url. template-url should point to a valid Angular template for a single suggestion item (which will be wrapped inside a <li> tag), and ng-atp-suggestions expose the scope variable suggestion for your template, as well as setting the class of the corresponding item to "selected" from user interactions (hover, and arrow key press). An example template may look like this:

<ul ng-atp-suggestions template-url="partials/mytemplate.html">
mytemplate.html:

<div>
  <i class="fa {{ suggestion.icon }}"></i>
  <span>{{ suggestion.label }}</span>
  <img src="{{ suggestion.url }}">
</div>

Details

ngAtp implements Twitter Bloodhound as a Angular service, ngBloodhound uses Angular's $http service as opposed to jQuery $.ajax in the original version (inspired by twhitbeck/angular-bloodhound). Other than that, suggestions are entirely managed by Bloodhound with all its prefetching, intelligent caching, fast lookups, and backfilling. On the rendering/directive side of things, ngAtp relies on ng-model and ng-repeat (without filtering, which is handled by Bloodhound), and tries to stick to default Angular directives as much as possilbe.

Dependencies

Angular

License

MIT

More Repositories

1

wontun

write your own vpn
Rust
83
star
2

rust-snake-wasm

A snake game in rust and webassembly
Rust
57
star
3

redux-free-flow

Free Monad Action Creators for Redux
JavaScript
40
star
4

basic_rs

Original Dartmouth BASIC Interpreter/Compiler
Rust
38
star
5

gensim-doc2vec-spark

just a prototype
Python
32
star
6

Pervasive-GRE

GRE vocabulary helper, highlight and add tooltip-definitions for GRE level words on any webpage.
JavaScript
27
star
7

A-R-Script-to-Download-Option-Quotes-from-Yahoo--Finance

Based on Martin Keller-Ressel's original script
R
7
star
8

vqn

A simple VPN based on QUIC
Rust
5
star
9

relooper

Relooper algorithm implemented in Rust
Rust
4
star
10

react-query-param

react-query-param
JavaScript
3
star
11

Stack-of-R-scripts

R
3
star
12

hnfontsize

Chrome Extension to adjust Hackernews font size live.
JavaScript
3
star
13

hn-activities-in-bq

HTML
2
star
14

yiransheng.github.io

site
HTML
2
star
15

Option-Quotes

A GAE application that scrapes option quotes via a CRON job.
Python
2
star
16

yiransbookmark

my bookmark app
Python
2
star
17

content-aware-ad-blocker

Project Name TBD
Jupyter Notebook
2
star
18

MagmaTNT

A Small Minecraft Mod
Java
1
star
19

HEAD

ActionScript
1
star
20

grid-assistant

Small js utility to draw a bootstrap like grid columns for an DOM element
JavaScript
1
star
21

vectorjs

small vector calculation lib
JavaScript
1
star
22

yiransbookmark-front-end

Angular front-end for my bookmark app
HTML
1
star
23

redux-login-examples

Redux login flow exampe with saga and loop
JavaScript
1
star
24

redux-loop-statemachine

DFA abstraction for redux with redux-loop
JavaScript
1
star
25

comment-thread-prototype

prototype
JavaScript
1
star
26

learningcurve

Utility app to organize bookmarks, documentations, online resources. Written in Backbone.js.
JavaScript
1
star
27

jQuery.splitList

split a list (or any html markup) into many identical ones
JavaScript
1
star
28

d3-piechart-callout-layout

Some graph algorithm
Rust
1
star
29

parse_expr

A simple javaScript expression parser
JavaScript
1
star
30

rust-toy-redis

Learning project, try to write a functioning redis-server for some basic commands
Rust
1
star
31

my-gae-blog

powered by Sinecere
Python
1
star
32

make-a-js-framework

A toy example of MVI with React and Redux-like api
JavaScript
1
star
33

html5lab

my lab for html5/javaScript experiments
1
star
34

Some-ActionScript-Remains

ActionScript
1
star