如何检查按钮是否第二次单击?

时间:2019-05-24 01:48:18

标签: html angular

我在html中有一个按钮,我想使搜索栏在单击时出现,并使其在第二次单击时消失。我已经知道如何做第一个,但是我不知道如何做第二个。

1 个答案:

答案 0 :(得分:2)

好像您要的是切换开关,开/关或真/假状态。只需在组件中声明一个局部变量,并将其初始设置为false。单击按钮后进行更改-

    <button (click)="onClick()">
    <div *ngIf="showSearchbar">this is searchbar</div>
    showSearchbar: boolean;

    onClick() {
      this.showSearchbar = !this.showSearchbar;
    }