my project requirement is to create an autocomplete search box which fetches data from elastic search . i will make it simple i have a textbox on which its onChange() event fires the autocomplete webservice and fetches the data. i am using angularjs 1.6 .
<input type="text" ng-change="fetchTags ()" ng-model="autocompleteData.text"/>
javascript
$this.fetchTags = function() {
    try {
        //remove special chars/
        $this.autoCompleteData.text = purgerFilter($this.autoCompleteData.text);
        //cancel previous timer;
        if (autoCompleteTimer) {
            $timeout.cancel(autoCompleteTimer);
        }
        //to avoid late response display suggesion list
        $this.autoCompleteData.hasEmitted = false;
        var txt = $this.autoCompleteData.getText();
        if (typeof txt !== undefined) {
            //200ms debounce.
            var time = 200;
            if (txt.length > 0) {
                autoCompleteTimer = $timeout(function() {
                    $this.autoCompleteData.newTag = undefined;
                    initiateGetTopicTagsFromWebService();
                }, time);
            } else {
                $this.autoCompleteData.setIsVisible(false);
            }
        }
    } catch (e) {
        throw e;
    }
};
everything is working fine. dont go to other function calls. my problem is in this function.
so here is whats happening : 1.if i normally start typing everything works , i get the actucal and proper response as per keywords.
2.if i delete normally . i,e from last character to first it is working fine.
3.the problem case : if i had to remove the initial characters . eg my textbox word is java script. and i decide to remove the ending a from java . the service will be called with "jav script" which i dont want. this case should not case change function to fire.
this configuration i want in my autocomplete search textbox.
 
    