如何在angular2 formControl中使用ngFor
how to use ngFor in angular2 formControl
我尝试使用 formcontrolName 绑定来自 ngFor 的 json 数据,但我不知道如何绑定它。我的方法不行,有人知道吗?
<p *ngFor="let user of searchuser" formControlName="username">{{user.username}}</p>
<p *ngFor="let tool of searchtool" formControlName="rfidCode">{{tool.rfidCode}}</p>
大概是这样的:
<p *ngFor="let user of searchuser;let idx=index" formControlName="username{{idx}}">{{user.username}}</p>
<p *ngFor="let tool of searchtool;let idx=index" formControlName="rfidCode">{{tool.rfidCode + idx}}</p>
formControlName
需要独一无二,但我需要更多关于您的实际需求的信息才能提出更具体的建议。
顺便说一句:formControlName
用于输入元素,而不是用于 <p>
元素。
https://angular.io/docs/ts/latest/api/forms/index/FormControlName-directive.html
我尝试使用 formcontrolName 绑定来自 ngFor 的 json 数据,但我不知道如何绑定它。我的方法不行,有人知道吗?
<p *ngFor="let user of searchuser" formControlName="username">{{user.username}}</p>
<p *ngFor="let tool of searchtool" formControlName="rfidCode">{{tool.rfidCode}}</p>
大概是这样的:
<p *ngFor="let user of searchuser;let idx=index" formControlName="username{{idx}}">{{user.username}}</p>
<p *ngFor="let tool of searchtool;let idx=index" formControlName="rfidCode">{{tool.rfidCode + idx}}</p>
formControlName
需要独一无二,但我需要更多关于您的实际需求的信息才能提出更具体的建议。
顺便说一句:formControlName
用于输入元素,而不是用于 <p>
元素。
https://angular.io/docs/ts/latest/api/forms/index/FormControlName-directive.html