My question is very similar to this post 'Using typeahead and ajax in a AngularJS app'
Coffeescript:
$scope.tradingPartners = (searchOn) ->
console.log("Searching on #{searchOn}")
$.getJSON("../tp/tpLookupAdmin", {term: searchOn, max: 20}, (response)->
response)
Generates Javascript:
$scope.tradingPartners = function(searchOn) {
console.log("Searching on " + searchOn);
return $.getJSON("../tp/tpLookupAdmin", {
term: searchOn,
max: 20
}, function(response) {
return response;
});
};
Using it:
<input type="text" ng-model="testScript.sender" typeahead="sender as sender.label for sender in tradingPartners($viewValue)"
So whats wrong? ...
The getJSON call is made just fine, the results look good but the typeahead does not do anything. If I put hardcoded values in as the return from the function it works just fine.
Now I know the getJSON is not just returning an object array, and doing
$.getJSON("../tp/tpLookupAdmin", {term: searchOn, max: 20}, (response)->
response).responseJSON
gives undefined.
Example hardcoded json that works:
[{"id":"1","label":"test1"},{"id":"2","label":"test2"}]
I'm missing something simple here...