angular - 使用带有比较运算符的 ng-if
问题描述
我创建了一个组件“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 无法按预期工作,因为它会打印所有值。