Link to home
Start Free TrialLog in
Avatar of erzoolander
erzoolander

asked on

Angular Input Autocomplete/PHP/MySQL

I'm looking to write a routine in Angular that will serve as a search/autocomplete function on an input.  

The examples that I see, however, on the tutorial sites are problematic though...IMHO.  They all put into the name scope the entire list.  The examples I see are all along the lines of:

var app = angular.module('myApp', ['ui.bootstrap']);
 
app.controller('autocompleteController', function($scope, $http) {
 getCountries(); // Load all countries with capitals
 function getCountries(){
 $http.get("ajax/getCountries.php").success(function(data){
 $scope.countries = data;
 });
 };
});

Open in new window


which might be all well and good for something like a country list - where there are only X number of possible options.  Might as well just download the whole list and then sift through them.

But - what if there are thousands of possible options?  What I'd like is a query where every time the input changes (I assume on an onChange event) - the ajax query is fired again...so in the above example it would be like...

function getCountry(country) {
var app = angular.module('myApp', ['ui.bootstrap']);
 
app.controller('autocompleteController', function($scope, $http) {
 getCountries(); // Load all countries with capitals
 function getCountries(){
 $http.get("ajax/getCountries.php?country="+country).success(function(data){
 $scope.countries = data;
 });
 };
});
}

Open in new window


Is that about the syntax I'd use?  I'm pretty new to Angular and have had dicey results trying to change scopes on the fly like that.
ASKER CERTIFIED SOLUTION
Avatar of erzoolander
erzoolander

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial