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

typescript – Angular2 viewmodel中的布尔值不更新* ngIf模板

发布时间:2020-12-17 08:45:58 所属栏目:安全 来源:网络整理
导读:我有一个奇怪的行为,我需要一些帮助.这是一个angular2和打字稿应用程序. 我有一个模板,其中包含以下使用ngIf的html: div *ngIf="loading" class="row" div class="small-3 small-centered columns" img src="/Images/loading_spinner.gif" / /div /div 我有
我有一个奇怪的行为,我需要一些帮助.这是一个angular2和打字稿应用程序.

我有一个模板,其中包含以下使用ngIf的html:

<div *ngIf="loading" class="row">
        <div class="small-3 small-centered columns"  >
            <img src="/Images/loading_spinner.gif" />
        </div>
    </div>

我有一个按钮,触发一个函数来改变加载的值

export class ShiftEditComponent implements OnInit {

    loading: boolean = false;

    setLoading(value: boolean): void {
        if (this.loading !== value) {
            this.loading = !this.loading;
        }
    }
}

这是奇怪的事情.如果我从类中的其他位置指定value参数的值,则模板不会更新.但是如果我去除逻辑并且只是将负载分配给它的相反,那么它工作并且模板更新并且ngIf显示并且不相应地显示.

这个工作:

setLoading(): void {
            this.loading = !this.loading;
    }

题:
当我只是分配相反的值时,为什么这会工作和ngIf更新,但如果我尝试通过参数指定值,则ngIf模板不会更新(显示或隐藏)

If i specify the value of the value parameter from somewhere else in the class,the template does not update

一个常见的症状是你在那个处理程序中有错误

固定

使用箭头功能https://basarat.gitbooks.io/typescript/content/docs/arrow-functions.html

(编辑:李大同)

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

    推荐文章
      热点阅读