angularjs - Convert $http request to Restangular -
i'm trying use angular-ui bootstrap typeahead search names remote server.
input search field implemented follows.
<input type="text" ng-model="selectedname" typeahead="name name in search($viewvalue)" class="form-control">
and equivalent controller code follows.
$scope.search = function (term) { return $http({ method: 'get', url: 'names/search.json', params: { q: term } }).then(function (response) { var names = []; (var = 0; < response.data.length; i++) { names.push(response.data[i]); } return names; }); };
currently, working fine using $http
i'm trying use restangular server communication.
i've tried changing above controller code follows doesn't work.
$scope.search = function(term) { return restangular.all('users').one('search').getlist({q:term}).then( function(names) { return names.plain(); } ) };
with above implementation, response server fine expect [object object]
shown in dropdown instead of names.
how can convert above $http
request use restangular
?
enhanced promises -
$object: returns reference object filled once server responds value. means if call getlist empty array default. once array returned server, same $object property filled results server.
restangular.all("filter").getlist().$object
Comments
Post a Comment