【问题标题】:Type script variable is not getting updated in html after calling a function in angular 6在 Angular 6 中调用函数后,类型脚本变量未在 html 中更新
【发布时间】:2019-05-09 20:22:16
【问题描述】:

示例程序 TS:

thunderSuperDrop$ = false;
public action = {
    superDropActivate(){
        this.thunderSuperDrop$ = !this.thunderSuperDrop$;
        console.log(this.thunderSuperDrop$);
    }
}

HTML:

<div class="header-links same-line" 
(click)="action.superDropActivate()"></div>{{thunderSuperDrop$}}

最初变量thunderSuperDrop$ 设置为false 并出现在DOM 中。应用正常工作的功能后,它没有得到刷新。

【问题讨论】:

    标签: html typescript angular6


    【解决方案1】:

    试试这个方法

    superDropActivate(){
        this.thunderSuperDrop$ = true;
        console.log(this.thunderSuperDrop$);
    }
    

    HTML

    <div class="header-links same-line" 
    (click)="superDropActivate()">{{thunderSuperDrop$}}</div>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-25
      • 1970-01-01
      • 2019-03-01
      • 2012-12-26
      • 1970-01-01
      • 2015-09-27
      • 2017-03-16
      • 1970-01-01
      相关资源
      最近更新 更多