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

almighty-autocomplete

v1.1.0

Published

Simple to use autocomplete directive in a module for AngularJS

Downloads

3

Readme

allmighty-autocomplete

Simple to use autocomplete directive in a module for AngularJS! Supports arrow keys to traverse suggestions as well as mouse input. You can load the suggestions from a remote REST API, it also supports promises.

Checkout the demo to see what it does.

Setup

To use it you need of course AngularJS, so make sure it is loaded first. I always like to use Google's CDN for that:

  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular.min.js"></script>

Also you should load the stylesheet of the autocomplete:

  <link rel="stylesheet" href="style/autocomplete.css">

Then in your HTML you should load it before the script of your main app. Like this:

<script type="text/javascript" src="script/autocomplete.js"></script>
<script type="text/javascript" src="script/app.js"></script>

In your main script file you should add it as dependency:

var app = angular.module('app', ['autocomplete']);

Usage

If you now want an autocomplete you can just use the tag <autocomplete> tag in your HTML. With the data parameter you can pass in an array that will be used for autocompletion. You need to pass there something which is available in the $scope of your controller.

You can also pass a function that receives changes with the on-type attribute. This is useful if you need to load external resources from a REST API, for example, you can then upload the array you passed into data and it will automatically use the changed array.

Attributes

data : Pass an array to the autocomplete directive. Should be accessible in the $scope of your controller.

on-type : (optional) Pass a function that will receive changes, when somebody types something. It passes the full string for any character typed or deleted. You can use that for example to update the array that you passed in data.

on-select : (optional) Pass a function that will receive changes, when a suggestion is selected. It passes the full string of the suggestion.

click-activation : (optional) When true, the suggestion box opens on click (unfortunately onfoucs is not implemented properly in most browsers right now). By default it is only activated, when you start typing something.

ng-model: What you typed in will be in this variable and accessible in the $scope of the controller.

attr-placeholder: (optional) Sets desired text as placeholder into the input element of autocomplete directive. By default it's "start typing..."

attr-class: (optional) Change the class of the div containing the input and suggestions elements, allowing you to change their style according to your needs.

attr-id: (optional) Change the id of the containing div element, see attrs-class.

attr-input-class: (optional) Set the class of the input element, allowing you to style the input field directly.

attr-input-id: (optional) Change the id of the input element, see attrs-input-class.

autocomplete-required: (optional) This attribute provides value for an ng-required attribute on the directive's input field.

no-auto-sort: (optional) This attribute prevent the library to sort the data by alphabetical order.

Example

HTML:

    <div ng-controller="MyCtrl">
      <autocomplete ng-model="yourchoice" data="movies" on-type="updateMovies"></autocomplete>
    </div>

JavaScript:

	var app = angular.module('app', ['autocomplete']);

	app.controller('MyCtrl', function($scope, MovieRetriever){
		$scope.movies = ["Lord of the Rings",
		 				"Drive",
		 				"Science of Sleep",
		 				"Back to the Future",
		 				"Oldboy"];

		// gives another movie array on change
		$scope.updateMovies = function(typed){
			// MovieRetriever could be some service returning a promise
		    $scope.newmovies = MovieRetriever.getmovies(typed);
		    $scope.newmovies.then(function(data){
		      $scope.movies = data;
		    });
		}
	});

Change log

07.03.2014

  • attr-input-class & attr-input-id allow you to choose class and id of the input field. Handy when wanting to add bootstrap styles to the input field

25.02.2014

  • attr-class & attr-id allow you to choose class and id of the div where the autocomplete is contained, makes it more customizable
  • placeholder renamed into attr-placeholder

14.02.2014

  • got rid of jQuery dependency

13.02.2014

  • ng-model can now be used outside to obtain the current search parameter
  • hiding suggestions on blur

31.01.2014

  • Stop showing suggestions on pushing escape
  • select if suggestions should be shown after clicking on input with new parameter click-activation
  • Added customizable placeholders for input line
  • FIXED multiple autocomplete directives in one controller are now possible and behave as expected