I'm using angular bootstrap typeahead
. I would like to add a functionality for infinite scroll
in that, for that i have added a small directive for scroll functionality and some changes in typeahead
template, scroll directive works as expected but typeahead not updating a view after result is update.
My input is like :
<input type="text" ng-model="variable" placeholder="Search..." typeahead="obj as obj.text for obj in getObject($viewValue)" typeahead-wait-ms="500" />
typeahead template :
<ul class="dropdown-menu typeahead-custom" ng-scroll="getObject('{{query}}')" ng-scroll-direction="down" ng-show="isOpen()" ng-style="{top: position.top+'px', left: position.left+'px'}" style="display: block;" role="listbox" aria-hidden="{{!isOpen()}}">
<li ng-repeat="match in matches track by $index" ng-class="{active: isActive($index) }" ng-mouseenter="selectActive($index)" ng-click="selectMatch($index)" role="option" id="{{match.id}}" should-focus="isActive($index)">
<div typeahead-match index="$index" match="match" query="query" template-url="templateUrl"></div>
</li>
</ul>
and getObject Function :
$rootScope.lastResult = [];
$rootScope.getObject = function(str) {
return $http({
url: "someUrl",
method: "post",
headers: {'Content-Type': 'application/json'},
data: {str: str, page_limit: 10}
}).then(function(response) {
$.merge($rootScope.lastResult, response.data.data);
return $rootScope.lastResult;
});
};
when I type something in typeahead input it works fine, but when i scroll into the typeahead template it calls a function and updating lastResult
variable but didn't updating a DOM element of typeahead.
Any help? Please....
$scope.apply()
after result update? – Manoff