HTML:
<select [(ngModel)]='i.PaycodeId'>
<option *ngFor="let j of payCode" [value]='j.ID'>{{j.value}}</option>
</select>
Run Code Online (Sandbox Code Playgroud)
payCode:
[{"ID":0,"value":"Cycle"},{"ID":1,"value":"Truck"},{"ID":2,"value":"Car"}]
Run Code Online (Sandbox Code Playgroud)
在i.PaycodeId,通过ngModel,它将数字设置为字符串值而不是数字,"1"/"2"而传递给选择的值是具有ID值作为数字的对象.我希望这个值只是数字.
当我在标签中写动态"for"属性时,我得到错误.
例:
<div *ngFor="let question of questions; let i = index;">
<input id="ques-{{i}}" type="radio" name="selected" [value]="question">
<label for="ques-{{i}}">{{question.data}}</label>
</div>
Run Code Online (Sandbox Code Playgroud)
错误 :
未处理的Promise拒绝:模板解析错误:无法绑定到'for',因为它不是'label'的已知属性.
动态"id"属性工作正常,请帮我找一个解决方案