I'm having a problem with typeahead. I want to fetch a list of Account objects with my service class when user types some input. I need to store the Id of account object to use it in a different operation.
I've seen a lot of questions answered on this and I tried to apply the solutions but my service call doesn't even get triggered. As if the input had no functions supplied. Could someone point me what ridiculous mistake I'm making.
Ta
var myCtrl = angular.module('myControllers', ['myApp.myServices', 'ui.bootstrap'])
.controller('myController', function ($scope, $q, $filter, myService) {
$scope.selectedAccount = undefined;
$scope.loadingAccounts =false;
$scope.getAccounts = function(viewVal){
$scope.loadingAccounts = true;
console.log('I wish I saw this in logs : getAccounts for search terms '+ viewVal);
myService.searchAccounts(viewVal)
.then(
function (accountsList) {
$scope.loadingAccounts = false;
return accountsList;
},
function (errorMessage) {
$scope.loadingAccounts = false;
}
);
};
}
And the page
<input type="text" id="customer" placeholder="Search Accounts"
ng-model="selectedAccount" typeahead-min-length="2" typeahead-wait-ms="300"
typeahead="account as account.Name for account in getAccounts($viewValue)" />
<i ng-show="loadingAccounts" class="glyphicon glyphicon-refresh"></i>
links I researched link 1
example jsfiddle
a blog with delay attribute used
example plunker