我正在使用此angular port進行選擇。在我看來,我有兩個選擇元素,這兩個元素都有數千個需要向用戶顯示的選項,但我不認爲一次查詢所有選項然後將其卸載到用戶的電腦。獲取有關角度選擇的輸入更改的當前文本
相反,我想要聽取角度選擇輸入的鍵盤更改,然後將當前文本輸入值發送回服務器以獲取自動完成選項的較短列表。
在jQuery中,這將是類似於:
$(".selectize-input_1").on('input', function() {
var current_text = $(".selectize-input").val();
$.get("/autocomplete", current_text, function(options) {
// Set new autocomplete options for selectize
});
})
對角selectize,我有我的角度服務,做一個$http.post(current_text)
,但我不太清楚如何監聽的變化文本輸入(並獲取當前文本值)。 original selectize usage建議onChange
事件和query
爲raw_input將是路要走。然而,下面什麼也不做:
$scope.config_one = {
create: true,
valueField: 'id',
labelField: 'name',
delimiter: ',',
onChange: function(value) {
// Nothing happens when typing into input
console.log(value);
}
}
$scope.options_one = ['one', 'two']
<selectize config="config_one" options="options_one" ng-model="test"></selectize>
而且我不知道如何得到query
。如何監聽輸入內容的變化並獲取當前文本?