我正在为我的应用程序使用Angular-ui Bootstrap。 我使用typeahead指令。typeahead angular ui - 无法读取未定义的属性“长度”
HTML:
<input type="text" class="pass_code_input" ng-model="SuppPrefix" Typeahead="ddl_item.Text for ddl_item in getData($viewValue)"/>
控制器
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
});
};
};
服务:
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;
};
};
我收到从数据服务器,但我无法在屏幕上显示它。当我在Chrome浏览器开发工具来运行调试器,我得到了一个错误:
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)
我搜索了在多个地方的解决方案,如that,也跟着一步一步的引导用户界面主页上的说明进行操作。 我做错了什么?
你没有成功返回数据的方法,但期望它在你的控制器 – harishr
我试过了,它没有帮助。 另外,当我调试时,我看到控制器中的数据(它带有承诺)。数据甚至从控制器返回,但然后我得到这个错误。 – Lichte
你可以请安装一个笨重的,会给你快速解决 – harishr