Lempkin
Lempkin

Reputation: 1578

Angular : why this ng-if doesn't work?

I have this code in my app :

Template :

  <ng-container ng-if="cpt < 3">
    {{cpt}}
    <button pButton type="button" (click)="incrementCpt()" label="+"></button>
  </ng-container>

Component :

public cpt: number = 0;
...
  incrementCpt() {
    this.cpt++;
  }

But the button is never hidden. I don't understand why?

Upvotes: 0

Views: 61

Answers (3)

Shikha23
Shikha23

Reputation: 1

Because you have not use * with ngIf
Use like this

*ngIf="cpt < 3"

Upvotes: 0

Clyde
Clyde

Reputation: 93

<button pButton type="button" (click)="incrementCpt().bind(this)" label="+"></button> 

have you tried that too ?

Upvotes: 0

Rahul Singh
Rahul Singh

Reputation: 19622

if should be *ngIf instead of ng-if

Upvotes: 2

Related Questions