angularjs - 为什么我们在没有延迟参数的情况下调用 $timeout。

标签 angularjs

这个问题在这里已经有了答案:





Why is setTimeout(fn, 0) sometimes useful?

(19 个回答)


5年前关闭。




我正在尝试阅读一些 angularjs 代码
有一点在没有延迟参数的情况下调用 $timeout 。

dataBinding: () => {
            this.$timeout(() => {
                this.selectedRow = null;
            });
        },

这样做的目的是什么?

最佳答案

在这种情况下 (angular.js),这是一种解决方法 - 当您只想将您的操作推迟到下一个 angular 摘要周期时(并确保在当前摘要周期中不会发生这种情况)。

如果是这种情况,最好使用 $scope.$evalAsync()以此目的。
http://www.bennadel.com/blog/2605-scope-evalasync-vs-timeout-in-angularjs.htm

关于angularjs - 为什么我们在没有延迟参数的情况下调用 $timeout。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34333425/

相关文章:

javascript - CORS 错误 :Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response

javascript - AngularJS 组件 - 带有 Typescript 的 ngModelController

javascript - 使用拦截器处理 Ionic App 中的离线数据

javascript - 如何向 Angular 常量注入(inject)服务

javascript - Angular JS - UI路由器页面重新加载不会设置状态

javascript - Createjs 和 Angularjs : Cannot read property 'Stage' of undefined

javascript - Nativescript 未检测到 ScrollView 上的滑动事件

angularjs - 如何使用 AngularJS 在 Controller 中调用服务功能?

php - 从 ngThumb 指令上传 AngularJS 文件(使用 angular-file-upload)

javascript - angular ng-repeat后如何访问图像属性?