【问题标题】:AngularJS timeout AJAX callAngularJS 超时 AJAX 调用
【发布时间】:2014-06-15 03:15:11
【问题描述】:

在下一个示例中,我修改了事件,所以现在点击按钮时调用是 on-change:

<input type="text" ng-model="keywords" ng-change="search()"/>

a-simple-search-with-angularjs-and-php

如何添加延迟/超时,以便脚本在进行 AJAX 调用之前等待一秒钟? (即让用户有时间在拨打电话之前完成输入)

【问题讨论】:

    标签: ajax angularjs timeout delay


    【解决方案1】:

    尝试在 search 范围内添加函数 $timeout

    例子:

    function Ctrl($scope, $timeout) {
        $scope.search = function() {
            $timeout(function(){
    
              /* Execute your script */
    
            }, 1000); //add timeout 
        }
    }
    

    【讨论】:

    • 不是这样工作的:/* 执行你的脚本 */ alert('test');
    【解决方案2】:

    Angular 1.3,只需在模型上添加一个 debounce 选项

    <input type="text" ng-model="keywords" ng-model-options="{debounce: 1000}">
    

    关于 ngModelOptions 的文档:

    https://docs.angularjs.org/api/ng/directive/ngModelOptions

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-21
      • 2017-09-08
      • 2012-12-15
      • 2011-01-12
      • 1970-01-01
      • 2016-09-24
      • 2020-07-28
      • 2011-09-26
      相关资源
      最近更新 更多