I am using Angular-ui Bootstrap for my application. I use the typeahead directive.
html:
<input type="text" class="pass_code_input" ng-model="SuppPrefix" Typeahead="ddl_item.Text for ddl_item in getData($viewValue)"/>
Controller
function AutoCompleteCtrl($scope,$http, AutoCompleteSrv) {
$scope.getData = function (prefix) {
AutoCompleteSrv.GetAutoComplete("Supplier", prefix).then(function (result) {
var results_arr = [];
angular.forEach(result.data, function (item) {
results_arr.push({ "Val": item.Val, "Text": item.Text });
});
return results_arr
});
};
};
service:
function AutoCompleteSrv($http) {
var _$http = $http;
self = this;
self.GetAutoComplete = function (DataType, Prefix) {
var promise = _$http({
method: "GET",
url: 'api/AutoComplete',
params: { 'DataType': DataType, 'Prefix': Prefix }
}).success(function (data, status, headers, config) {
}).error(function (data, status, headers, config) {
});
return promise;
};
};
I do recieve the data from server, but I can't display it on the screen. When I run debugger in chrome dev tools, I get the next error:
TypeError: Cannot read property 'length' of undefined
at http://localhost:52145/js/libs/ui-bootstrap-tpls-0.11.0.min.js:13:12650
at m.promise.then.u (http://localhost:52145/js/angular/angular.min.js:97:280)
at m.promise.then.u (http://localhost:52145/js/angular/angular.min.js:97:280)
at http://localhost:52145/js/angular/angular.min.js:98:417
at h.$eval (http://localhost:52145/js/angular/angular.min.js:108:482)
at h.$digest (http://localhost:52145/js/angular/angular.min.js:106:62)
at h.$apply (http://localhost:52145/js/angular/angular.min.js:109:287)
at HTMLInputElement.l (http://localhost:52145/js/angular/angular.min.js:133:191)
at http://localhost:52145/js/angular/angular.min.js:31:32
at q (http://localhost:52145/js/angular/angular.min.js:7:386)
I've searched for solution in multiple places, like that, and also followed step by step the instructions in the bootstrap ui home page. What did I do wrong?