[英]Angular 2 ngSwitch nested in ngFor
What is the correct way to use an ngSwitch
within an ngFor
? 在
ngFor
使用ngSwitch
的正确方法是ngFor
?
If I do the following I receive the error 如果执行以下操作,则会收到错误消息
Got interpolation ({{}}) where expression was expected
在需要表达式的地方进行插值({{}})
<span *ngFor="let action of actions">
<span [ngSwitch]="{{action}}">
<span *ngSwitchCase='edit'>Edit</span>
<span *ngSwitchCase='delete'>Delete</span>
</span>
</span>
在使用(...)
或[...]
绑定时,您不需要将变量插值到字符串,您可以按原样使用它来绑定它。
<span [ngSwitch]="action">
<span *ngFor="let action of actions">
<span [ngSwitch]="{{action}}">
<span *ngSwitchCase="'edit'">Edit</span>
<span *ngSwitchCase="'delete'">Delete</span>
</span>
</span>
For *ngSwitchCase
if the value is a string we need to pass it within double quotes and then with single quotes like above mentioned: *ngSwitchCase="'delete'"
对于
*ngSwitchCase
如果值是一个字符串,我们需要将其用双引号引起来,然后使用单引号将其传递,例如上面提到的: *ngSwitchCase="'delete'"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.