简体   繁体   English

Angular2 ng-if有什么问题

[英]What is wrong in Angular2 ng-if

I'm really new to angular, I have been through all ng-if questions and cannot seem to find the right answer. 我对angular真的很陌生,我已经经历过所有ng-if问题,而且似乎找不到正确的答案。

I have this: 我有这个:

<tr *ngFor="#position of positions">                               
<td>
 <div ng-if="position.way == 0">Long</div>
 <div ng-if="position.way == 1">Short</div>
 {{position.way}}
 </td>
</tr>

{{position.way}} is outputting either 1 or 0 as expected and is defined as a string in the model. {{position.way}}将按预期输出1或0,并在模型中定义为字符串。 But the two div's are both displayed no matter what position.way is. 但是无论位置如何,都将显示两个div。

I have tried wrapping 0 and 1 in quotes, I have tried tripple equality operator, same result. 我试过用引号将0和1换行,我试过三重等式运算符,结果相同。

What am I doing wrong here? 我在这里做错了什么?

The ng-if syntax is wrong. ng-if语法错误。 It should be: 它应该是:

<tr *ngFor="let position of positions">                               
<td>
 <div *ngIf="position.way == 0">Long</div>
 <div *ngIf="position.way == 1">Short</div>
 {{position.way}}
 </td>
</tr>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM