I'm programming a SPA with AngularJS. Right now, I have an input field that triggers a query with $http to a 3rd party API. The search is done on real time as I have a $watch bind with the input model.
My problem is that for whatever reason, the results will only appear when the full string is consistent with the result, not before.
For example, if I'm looking for Frank Sinatra, some results will appear when Frank is typed into the input, but once I'm at Frank Sin, completely unrelated results will appear (or results consistent with Sin, but not with the whole string, and the desired result, will only appear once the whole string is entered.
What I understand, is that the input won't treat the entered text as a whole, but as a sum of the different words, which makes the query missbehave.
I'm attaching my JS, maybe I did something wrong!
angular.module('myApp', ['ngResource'])
function Ctrl($scope, $http) {
var search = function(name) {
if (name) {
$http.get('http://api.discogs.com/database/search?type=artist&q='+ name +'&page=1&per_page=5').
success(function(data3) {
$scope.clicked = false;
$scope.results = data3.results;
});
}
$scope.reset = function () {
$scope.sliding = false;
$scope.name = undefined;
}
}
$scope.$watch('name', search, true);