当用户在设置菜单中选中了复选框时,我想禁用预先输入功能(id = searchSuggestions)。下面的代码仅适用于页面的重新加载,但不适用于会话期间。是否可以在会话期间禁用angular的typeahead实现?如果是这样,怎么样?
// Controller for Angular's Search implementation
app.controller('TypeaheadCtrl', function($scope, $http) {
$scope.selected = undefined;
// prefetch the results
var value = $('#searchSuggestions').is(':checked');
if (value == true) {
$.getJSON('/typeahead', function(response){
//parse your response and assign it
$scope.recentPopularQueries = response;
});
// Fire off the transcribe(words) function as soon as a choice is selected
$scope.onSelect = function ($item, $model, $label) {
$scope.$label = $label;
transcribe($scope.$label);
};
}
});
答案 0 :(得分:0)
使用范围模型创建一个复选框:
<input type="checkbox" ng-model="typeaheadActive">
在执行预先输入请求之前,将模型值添加到您的条件中:
// Controller for Angular's Search implementation
app.controller('TypeaheadCtrl', function($scope, $http) {
$scope.selected = undefined;
// prefetch the results
var value = $('#searchSuggestions').is(':checked');
if (value == true && typeaheadActive) {
$.getJSON('/typeahead', function(response) {
//parse your response and assign it
$scope.recentPopularQueries = response;
});
// Fire off the transcribe(words) function as soon as a choice is selected
$scope.onSelect = function ($item, $model, $label) {
$scope.$label = $label;
transcribe($scope.$label);
};
}
});