[英]Using *ngFor with ng-container and *ngIf
One section of my form contains a set of n radio buttons (we'll set n=3 here) which appear in the template as:我的表单的一个部分包含一组 n 个单选按钮(我们将在这里设置 n=3),它们在模板中显示为:
<input type="radio" name="variety" value="11" (click)="update($event)">SomeNameX
<input type="radio" name="variety" value="23" (click)="update($event)">SomeNameY
<input type="radio" name="variety" value="36" (click)="update($event)">SomeNameZ
Below the radio buttons I want to produce one of these when the appropriate SomeName is selected:在选择适当的SOMENAME时,我要在单选按钮下方提出其中一个:
<div *ngIf="selected===11">Last updated: Sept 1</div>
<div *ngIf="selected===23">Last updated: Oct 3</div>
<div *ngIf="selected===36">Last updated: Nov 4</div>
where the date and value for each SomeName are returned from the database.其中每个 SomeName 的日期和值是从数据库返回的。 I'm using the following code to do the work:
我正在使用以下代码来完成这项工作:
<ng-container *ngFor="let item of items;">
<div *ngIf="selected==={{item.id}}">
Last updated: {{item.dte}}
</div>
</ng-container>
This is failing because of the {{item.id}}
piece - how can I inject the correct value/id into that position?由于
{{item.id}}
片段而失败 - 我如何将正确的值/id 注入该位置?
不带表达式使用
<div *ngIf="selected === item.id">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.