ODataAngularResources
ODataAngularResources copied to clipboard
typeahead search not working
I am trying to get typeahead to work, it is working with $http.get but not with the odata library. Seems like it is a problem with returning the promise, not sure if I am missing something.
Works: return $http.get("/odata/Plants?$filter=substringof('"+val+"',Name)").then(function (response) { var data = response.data; return data.value; });
Returns data but typeahead doesn't get the return and hangs: appDb.Plants.odata().filter(new $odata.Func('substringof', new $odata.Value(val), new $odata.Property("Name"))).query(function (data) { return data; });
returns data but typeahead does nothing, doesn't even trigger loading indicator: return appDb.Plants.odata().filter(new $odata.Func('substringof', new $odata.Value(val), new $odata.Property("Name"))).query(function (data) { return data; });
Hi @FarmSol, this is because your library expects a promise, and you're giving it an array. You should use $q and return a proper promise.
Or maybe something like :
var plants = appDb.Plants.odata().filter(...).query();
return plants.$promise;
Some libraries (like angular grids) work well and expect the resource object and know how to check resourceObj.$promise to know when resourceObj array will be populated and to populate the grid. Others are just built around promises, so you'll have to implement some kind of adapter logic directing it to the $promise, I'm guessing the library would take the response from the properties on the $promise object rather than the resource object itself.
So just keep in mind, this library is a wrapper around the angular Resource object concept.
@devnixs Thanks!! returning .$promise worked