Utilizing the AngularJS Bootstrap typeahead module, I am attempting to showcase data from an array of objects. Despite receiving data from my API call, I keep encountering the following error:
TypeError: Cannot read property 'length' of undefined
This is the current state of the controller:
$scope.companySearch = function(val) {
LeadsService.getCompany(val)
.then(function(resp) {
return resp.resp;
});
};
And here is the directive:
<input typeahead="company as item.company_name for item in companySearch($viewValue)" id="companyName" name="company_name" type="text" class="form-control input-md" ng-model="companyDetails.company_name" typeahead-wait-ms="200" required>
Lastly, this is the data I am trying to retrieve:
[{"id":2,"company_name":"Test Company","address1":"abc","address2":"def","po_box":"1234","city_id":2,"email":"example@example.com","phone":"9898","fax_no":9798,"website":"www.example.com","corporate_code":null,"contact_person_first_name":"First","contact_person_last_name":"Last","contact_person_phone":"98989","contact_person_email":"example@example.com"}]
If it provides any insight, the error occurs before my promise is fulfilled.