小编Anu*_*hna的帖子

选中时传递所选复选框的 id(通过 ngFor 加载)

       <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>
Run Code Online (Sandbox Code Playgroud)

角度 componentx.html 中的示例输出: 在此输入图像描述

此代码根据提供的 noOfQuestions 和 noOfAnswers 生成一组复选框。我想在选中复选框时将复选框的特定 id 传递给函数“getAnswer”。ts 文件中传递的参数“id”值表示未定义。getAnswer() 的参数应该是什么来传递所选复选框的 id ???

html radio-button ngfor angular

5
推荐指数
1
解决办法
1318
查看次数

标签 统计

angular ×1

html ×1

ngfor ×1

radio-button ×1