How Autocomplete Done In Angularjs Using Directive And Factory

The Autocomplete textbox is used for providing a suggestion when we are typing into the input box (text field). You notice when we typing in the Google search, that is called Autocomplete. It is mostly used for instant search from the predefined or AJAX based listing.

Use of filters is also known part in Angularjs. Filters are used for filtering the data based on passed argument. Filters are used in template files in angularjs. In filters, we can use expressions as well. And we are going to use all these for getting the autocomplete functionality.
Example of filters in template file is,
Ex.(ng-repeat=”i in items | filtersearch:searchString”).
Here, filtersearch is a name of filter and ‘searchString’ is arguments that it will passed text parameter. Whatever we will put into the Textbox, it will be passed as an array and it will be stored as an elements of an Array.
Note: Here you also need to supply ‘searchString’ this as your ng-model name for input search box in web development service.
Let me walk you through how to create Autocomplete textfield 
1. Make a Simple form to create autocomplete textfield
Create a one input textfield, give a ng-change event in this text field
And give one ng-model name for this text field,and And Also Create a one select box it would be ‘multiple’ also give ng-style  because whenever user selects text from the list then selected item will be copied in the text box and we also need to hide the list.
<div>
<input type="text" ng-model="searchString"  ng-change="searching()" ng-keydown="changecursor($event)" id="input" autofocus><br>
<select id="select" ng-style="vis" ng-model="txt" ng-click="copy($event)" ng-keypress="copy($event)" ng-keydown="changecursor($event)” multiple>
<option ng-repeat="i in items | filtersearch:searchString">{{i.string}}</option>
</select >
</div>
Here, ng-model=”txt” is used for copy text into the text field.

Reaf more https://goo.gl/qrmAI8

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s