我正在爲我的應用程序使用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