【发布时间】:2020-01-10 11:55:34
【问题描述】:
<form name="check-boxes">
<div *ngFor="let quest of noOfQuestions">
<div class="form-check form-check-inline" *ngFor="let ans of noOfAnswers">
<label class="form-check-label">{{ans}}
<input class="form-check-input" type="checkbox" name="{{quest}}" id="{{quest}}{{type}}" value="{{ans}}" (change)="getAnswers(id)">
<span class="form-check-sign"></span>
</label>
</div>
</div>
</form>
angular componentx.html 中的示例输出:
此代码根据提供的 noOfQuestions 和 noOfAnswers 生成一组复选框。当检查复选框时,我想将复选框的特定ID传递到'getanswer'的功能。在 ts 文件中传递的参数 'id' 值,称为未定义。 getAnswer() 传递选中复选框的 id 的参数应该是什么???
【问题讨论】:
-
对象
quest有变量吗?它是什么类型的?也许你可以做(change)="getAnswers(quest.id)" -
任务只是一个数字
-
id="{{quest}}{{type}}"这是你的身份证对吧? -
是的,它是单选按钮的 ID
-
@AnupamaThathsarani 您也可以使用这种方法。 Click
标签: html angular radio-button ngfor