ODataAngularResources icon indicating copy to clipboard operation
ODataAngularResources copied to clipboard

typeahead search not working

Open ghost opened this issue 7 years ago • 4 comments

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; });

ghost avatar Mar 18 '17 20:03 ghost

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.

devnixs avatar Mar 20 '17 21:03 devnixs

Or maybe something like :

var plants = appDb.Plants.odata().filter(...).query();
return plants.$promise;

devnixs avatar Mar 20 '17 21:03 devnixs

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.

kyse avatar Mar 20 '17 21:03 kyse

@devnixs Thanks!! returning .$promise worked

ghost avatar Mar 20 '17 22:03 ghost