Abhijeet Panwar
Abhijeet Panwar

Reputation: 1867

Using ng-if with comparison operator

I have created a component 'OddComponent':

export class OddComponent implements OnInit {
  @Input() oddscore = 0;
  constructor() { }
  ngOnInit() {
  }
}

And it's html is:

<div ng-if="oddscore %2 ==0 ">
<p>
  odd works! {{oddscore}}
</p>
</div>

I am passing 'oddscore' variable from app component:

<app-odd [oddscore]="gameScore">
</app-odd>

My motive is to use ng-if to only print odd values in the component. But it seems that ng-if does not work as expected, as it prints all the values.

Upvotes: 1

Views: 1420

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222682

There is no issue with the comparision, You are using angularjs syntax with angular, it should be *ngIf

<div *ngIf="oddscore%2 ==0 ">

STACKBLITZ DEMO

Upvotes: 1

Related Questions