将 ng-if 与比较运算符一起使用

Using ng-if with comparison operator

我创建了一个组件'OddComponent':

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

它的 html 是:

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

我正在从应用程序组件传递 'oddscore' 变量:

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

我的动机是使用 ng-if 只打印组件中的奇数值。但是 ng-if 似乎没有按预期工作,因为它打印了所有值。

比较没有问题,您正在使用 angularjs 语法和 angular,它应该是 *ngIf

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

STACKBLITZ DEMO