加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 角度2,如何使用setTimeout?

发布时间:2020-12-17 09:15:18 所属栏目:安全 来源:网络整理
导读:在登录页面中,当我们提交页面时,我有这个功能: checkLogin(){ this.x_userS.getLogin(this.x_userO.login_name,this.x_userO.pwd_plain).then(response = this.x_userO=response); (function(){ setTimeout(() = { if (this.x_userO.login_status == "1") {
在登录页面中,当我们提交页面时,我有这个功能:
checkLogin(){
    this.x_userS.getLogin(this.x_userO.login_name,this.x_userO.pwd_plain).then(response => this.x_userO=response);
    (function(){
        setTimeout(() => {
            if (this.x_userO.login_status == "1") {
                this.x_companyS.getCompanyByUser(this.x_userO.user_id).then(response => this.x_companyO=response);
                (function(){setTimeout(() => {
                    this.x_userS.setUser(this.x_userO);
                    this.x_companyS.setCompany(this.x_companyO);
                    this.router.navigate(['HomePage']);
                },2000);
            })();
            }
            else {
                window.alert("oops");
            }
        },2000);
    })();
}

其中x_userS是登录服务,x_userO是用户对象.我正在努力给予承诺两秒钟,以便在处理之前返回数据.没有setTimeout,它不会及时返回.

我尝试删除除了警报之外的所有内容,并在两秒钟后进行了验证.但是,它并没有识别出任何其他功能(){}的内容,所以我相信我需要传递所有的服务和对象.

有谁知道如何做到这一点?

如果你使用function(),那么这个.不会指向你的类中的变量.
Use()=>而是到处都是

setTimeout()周围的(function(){…})()似乎是冗余的.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读