我正在使用Angular Bootstrap UI typeahead并尝试更新 typeahead 中的模型值。但除非特别应用,否则更新的模型值不会反映更改。
<input ng-model="query" typeahead="option for option in getOptions($viewValue)">
app.controller('MainCtrl', function($scope) {
$scope.query = '';
$scope.getOptions = function(query){
if(query == "foo"){
$scope.query = "foobar";
// uncommenting the next line works but also raises error
// $scope.$apply()
return []
}
return ["I have an idea", "I have new idea"];
}
});
Plunker 代码: http ://plnkr.co/edit/pNxBMgeKYulLuk7DO0gB?p=preview