0

I'm trying to show a div based on whether button is clicked or not, however this doesn't seem to be working.

Component HTML

<button ng-click="showFormToggle()">Click</button>

<div ng-show="showForm">

</div>

I've also tried

<button (click)="showFormToggle()">Click</button>

<div *ngIf="showForm">

</div>

Component Typescript

 showForm: boolean = false;

 showFormToggle(){
    this.showForm = true;
    console.log(this.showForm);
  }
sander
  • 1,426
  • 4
  • 19
  • 46

2 Answers2

1

Based on your Component HTML, you may be confused as the version of Angular you are using. I am assuming you are intending to use Angular2+, considering your naming convention (Component vs Controller), and therefore the first example no longer works (That is AngularJS). component.ts

showForm : boolean = false;

component.html

<button (click)="showForm = !showForm">Click</button>
<div *ngIf="showForm">
</div>

or

<button (click)="showForm = !showForm">Click</button>
<div [hidden]="!showForm">
</div>

Please confirm what you are using, Angular 2+ or AngularJS.

Geoff Lentsch
  • 1,054
  • 11
  • 17
0

in your html:

<button (click)="showFormToggle()">Click</button>

            <div *ngIf="isChecked">
                Clicked!
            </div>

in your ts file, before the constructor:

isChecked = false;

and your function:

showFormToggle(){
    this.isChecked = !this.isChecked;
}

I hope it is what you are looking for!