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"];
}
});
プランカーコード: http://plnkr.co/edit/pNxBMgeKYulLuk7DO0gB?p=preview