Skip to main content
All CollectionsBatchDataAddress Autocomplete SDK
BatchData Address Autocomplete Angular Library V 1.0
BatchData Address Autocomplete Angular Library V 1.0
R
Written by RevOps
Updated over 2 months ago

Address Autocomplete enables users to quickly find and select from a pre-populated list of values as they type, leveraging searching and filtering.

This guide will get you started with integrating the Batch Address Auto Complete Angular Library with your applications. Everything about creating a Client Token, Installing the library and integrating it with your applications is covered in this guide.

Installation and Integration

Step 1: Download Library

Autocomplete library is registered as a package on npm. You can install the latest version with the npm CLI command

npm install @batchservice/batch-autocomplete-lib

As an alternative you can use the Yarn CLI command

yarn add @batchservice/batch-autocomplete-lib

Once the Library is downloaded, it is ready to be included in our applications.

Step 2: BatchData Client Token Generation

Create A client Token from you BatchData account. For steps to create a token refer Creating a Client Token

Step 3: Library Initialization

To begin using our downloaded library in our applications, we must first import our library into AppModule with authentication details as follows -

import { BatchAutocompleteLibModule } from '@batchservice/batch-autocomplete-lib';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
@NgModule({
imports: [ BatchAutocompleteLibModule.forRoot('URL', 'TOKEN')
],
schemas: [
CUSTOM_ELEMENTS_SCHEMA
]
})
export class AppModule {}

Replace URL with URL and TOKEN with the token generated in Step 2

Step 4: UI Integration

Create a typescript component file with following code or include the code in existing component file to make the functions accessible -

class <YourComponentName> { 
public recentSearch = [
// List of suggestions to be displayed before any input is provided in search input box. ];

selectEvent(item: any) {
// Do Your Execution with data
console.log('Selected item', item);
}

handleError(error: any){
// Handle error as you want
console.log(error);
}

suggestionList(data: any){
// Suggestion list data
console.log('suggestion list data', data);
}
}

Create new HTML component file with following code or include the code in existing component file -

<bs-address-autocomplete
[showNotFound]=true
notFoundText='Not found data'
placeholder='Enter your address'
displayData='name'
[debounceTime]= '700'
[take]=5
(suggestionList)='suggestionList($event)'
(selected)='selectEvent($event)'
(handleError)='handleError($event)'
[recentSearch]="recentSearch"
[filterType]="['address', 'formatted-street', 'zip']"
</bs-address-autocomplete>

Step 5: Configuration

Initially library will be configured with default configurations. You can update these parameters as required
โ€‹

showNotFound: This option is used to enable a notification for users when no results are found for the given string. By default it will be set as true. It can accept only boolean values.

notFoundText: This option is used to set the text to be shown when there are no results for the given input. By default it will set as No results found

placeholder: This option is used to set the text to be shown in the text input so that users will understand what are they expected to input. This text will be removed once user starts typing in. By default it will set as Enter your address

displayData: This option is used to populate the data in the input box when user selects a record from searched result. By default it will populate name parameter returned for selected item. You can set it to populate - state, address , name , zip , city.

take: This option is used to set the number of results to be displayed when input is typed. By default it is set to 5.

debounceTime : This option is used to delay the search API call when a user is typing the keyword in input box. For example, If the value is set to 700, the search API will get triggered after 700ms post last key stroke made within 700ms. By default this value is set to 700, It is recommended to keep this value at its default value to save the API calls.

suggestionList : The function provided in this parameter will be triggered when suggestion list is returned by API.

selected : The function provided in this parameter will be triggered when user selects an item from the suggestion list.

handleError : The function provided in this parameter will be triggered when there an error in API.

recentSearch : This parameter is used to set some pre-defined list of suggestions which can be displayed when user clicks on search input before any input is provided in the search box. This parameter should be set with array of suggestions as a key value pair as follows -

public recentSearch = [ 
{name: '8300 Apple'},
{name: 'Apple St'},
{name: '89001 Alamo'},
{name: '58651 Rhame'}
];

filterType : This option is used to filter the suggestion list by type of the property. By default the parameter will contain all the available types. You can keep the types you desire to get as a suggestion list. Allowed values are - zip,locality,state,formatted-street,address,building,city,county.

Well done!! You can begin using Batch Address Autocomplete component in your application by adding it on your webpage.

Now that your application has been integrated with Address Autocomplete, your users only have to type the first few letters of an address and your application will suggest addresses that begin with the letters they typed.

Clicking on any of the suggested addresses automatically prepopulates the address bar.

Did this answer your question?