因为AngularJS 1.6版本中的$typeahead parser已被删除,我们需要手动在$scope中添加该函数来实现typeahead。 下面是具体的
HTML代码:
JavaScript代码:
app.controller('MyCtrl', function($scope) {
$scope.items = [...]; //这里是item的数组
$scope.onSelect = function($item, $model, $label, $event) {
$scope.selected = $item;
};
// 添加$typeahead parser解决typeahead问题
$scope.$typeahead = function($viewValue, $index) {
var normalized = $scope.$normalize($viewValue);
return $scope.$eval($scope.$options.getter) || [];
};
});
上述代码将在AngularJS 1.6.9中正常工作,解决了typeahead的问题。