我有一个具有typeahead
和typeahead-input-formatter
属性的文本框,用于在用户开始输入时提供用户提示列表,并在angularjs模型中存储所选值,但在文本框中显示所选值的文本,对于axample如果要设置的模型值“jsmith”文本框将显示“John Smith”,并且当用户从建议列表中选择建议值时它工作正常,但是当我检索现有记录并使用'ng-触发typeahead-input-formatter
时init'它确实通过代码,但没有设置文本框的显示值:
HTML
<input ng-controller="TypeaheadCtrl" ng-init="travel.managerId"
ng-model="travel.managerId" type="text"
typeahead="suggestionEntry.userId as suggestionEntry.fullName for suggestionEntry in
activedirectory($viewValue)"
typeahead-input-formatter="formatLabel($model)">
app.js
travelApp.controller('TypeaheadCtrl', function ($scope, $http, limitToFilter) {
$scope.entries = [];
$scope.activedirectory = function (empName) {
return $http.get("api/activedirectory/GetActiveDirectoryEntries/" + empName).then(function (response) {
$scope.entries = response.data;
return limitToFilter(response.data, 20);
});
};
$scope.formatLabel = function (model) {
if ($scope.entries.length < 1 && model != undefined) {
$http.get("api/activedirectory/GetActiveDirectoryEntries/" + model).success(function (data) {
$scope.entries = data;
for (var i = 0; i < $scope.entries.length; i++) {
if (model == $scope.entries[i].userId) {
return $scope.entries[i].fullName;
}
}
}).error(function () {
alert('Error reading JSON file.');
});
}
for (var i = 0; i < $scope.entries.length; i++) {
if (model == $scope.entries[i].userId) {
return $scope.entries[i].fullName;
}
}
}
});
请告知。