百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
A

allmighty-autocomplete

> 编程语言
开源

AngularJs 模块中的简单易用的自动完成指令!

390 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

AngularJs 模块中的简单易用的自动完成指令!

allmighty-autocomplete

Warning! This code is not maintained anymore!

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:

xml
  

Also you should load the stylesheet of the autocomplete:

xml
  

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

xml

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

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

Usage

If you now want an autocomplete you can just use the tag `` 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:

xml
    

JavaScript:

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

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言