gpt4 book ai didi

javascript - 在范围内使用 Typeahead 和 AngularJS 加载数据会导致 "TypeError: Cannot call method ' then' of undefined"

转载 作者:行者123 更新时间:2023-11-30 06:25:34 25 4
gpt4 key购买 nike

尝试使用 this concept 时为了预先输入,我创建了以下代码(它适用于 json 数据,但不适用于此新数据):

HTML

<input type="text" ng-model="result" typeahead="suggestion for suggestion in instObjs($viewValue)">

JS

function NavbarCtrl ($scope, cService, $http, limitToFilter) {

$scope.institutions = [];

cService.getInstitutions().then(function(institutions){
$scope.institutions = institutions;
});

$scope.instObjs = function(institutions) {
return $scope.institutions.name.then(function(response){
return limitToFilter(response.data, 15);
});
};
};

最佳答案

看来,您正在尝试在分配之前使用 $scope.institutions.name。我想,在调用 cService.getInstitutions() 之前调用了 $scope.instObjs。

但这是结果,而不是原因

我可以看到您正在尝试访问数组的属性名称。你确定你不是这个意思吗:

$scope.instObjs = function(institutions) {
return institutions.name.then(function(response){
return limitToFilter(response.data, 15);
});
};

我的意思是使用函数的参数而不是数组。那是有道理的。这可能是一个原因

关于javascript - 在范围内使用 Typeahead 和 AngularJS 加载数据会导致 "TypeError: Cannot call method ' then' of undefined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21342842/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com