首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >控件属性设置为false后,ActivityIndicator不会关闭

控件属性设置为false后,ActivityIndicator不会关闭
EN

Stack Overflow用户
提问于 2018-12-10 20:32:43
回答 1查看 67关注 0票数 1

我使用Anuglar6和原生脚本,试图使ActivityIndicator显示时,我做的api工作(登录)。这很好用,但是在我将Boolean处理设置为false之后,它仍然显示旋转的动画。

代码语言:javascript
运行
复制
<StackLayout class="container">
  <StackLayout class="form">
    <Label class="h3 lbl" text="Användarnamn:" textWrap="true"></Label>
    <TextField class="field input input-border" [isEnabled]="!processing" keyboardType="email" autocapitalizationType="none" (textChange)="setUsername($event)" (returnPress)="focusPassword()"></TextField>
    <Label class="h3 lbl" text="Lösenord:" textWrap="true"></Label>
    <TextField #password class="field input input-border" [isEnabled]="!processing" secure="true" autocapitalizationType="none" (textChange)="setPassword($event)"></TextField>
    <Button class="loginBtn" text="LOGGA IN" [isEnabled]="!processing" (tap)="submit()"></Button>
    <ActivityIndicator row="1" [busy]="processing" width="100" height="100" class="activity-indicator"></ActivityIndicator>
  </StackLayout>
</StackLayout>

代码语言:javascript
运行
复制
    private processing = false;

    public login(): void {
    this.processing = true;
    this.authService.login(this.username, this.password)
        .subscribe(
            () => {
                console.log(this.processing);
                this.processing = false;
                console.log(this.processing);
                // this.router.navigate(['home']);
            });
}

console.log打印输出

代码语言:javascript
运行
复制
JS: true
JS: false

我在这里做错了什么?

EN

回答 1

Stack Overflow用户

发布于 2018-12-11 19:25:24

非常感谢你在这件事上的帮助。我不想再点击一次按钮来关闭ActivityIndicator。我想在登录任务完成后将其关闭。数据已更新,但ui未更新。我用BehaviorSubject解决了这个问题。

代码语言:javascript
运行
复制
public processing$ = new BehaviorSubject<boolean>(false);

public login(): void {
    this.processing$.next(true);
    this.authService.login(this.username, this.password)
        .subscribe(
            () => {
                console.log(this.processing$);
                this.processing$.next(false);
                console.log(this.processing$);
                this.router.navigate(['home']);
            });
}

现在,它相应地更新ui。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53705740

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档