在此处将 AngularJS 与 C# webapi 结合使用。
我正在创建一个输入控件,当用户开始输入时我想使用预输入并显示返回的数据。
我已经设置了 typeahead 如下:
HTML:
<input type="text" name="uName" ng-model="uName" autocomplete="off" required class="form-control input-medium" placeholder="Enter user name..."
typeahead="uName for uName in getUserNames($viewValue)" />
Controller :
$scope.getUserNames = function (search) {
myService.getUserNamesFromApi(search).then(function (response) {
$scope.foundNames = [];
if (response.length > 0) {
for (var i = 0; i < response.length; i++) {
$scope.foundNames.push({ 'uName': response[i].uName });
}
return $scope.foundNames;
}
});
};
从我的 API 返回的数据是一个数组,例如:
0: {fName: "Adam", lName: "Smith", uName: "asmith123"},
1: {fName: "John", lName: "Bambi", uName: "jbambi456"}
等等……
我正在尝试获取 uName 部分并将其推送到我的数组,然后返回该数组。但是目前这段代码没有显示任何内容,没有错误。
我在这里错过了什么?
最佳答案
应该是,
typeahead="uName as uName.uName for uName in getUserNames($viewValue)" />
关于javascript - AngularJS typeahead 调用 webapi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52319029/