选中的复选框(通过ngFor加载时的密码)被选中

问题描述 投票:0回答:1
       <form name="check-boxes">
          <div *ngFor="let quest of noOfQuestions">
            <div class="form-check form-check-radio form-check-inline" *ngFor="let ans of noOfAnswers">
              <label class="form-check-label">{{ans}}
               <input class="form-check-input" type="radio" name="{{quest}}" id="{{quest}}{{type}}" value="{{ans}}"  (change)="getAnswers(id)"> 
              <span class="form-check-sign"></span>
             </label>
            </div>
          </div>
      </form>

角度分量x.html中的样本输出:enter image description here

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

html angular checkbox ngfor
1个回答
0
投票

尝试一下:

       <form name="check-boxes">
          <div *ngFor="let quest of noOfQuestions">
            <div class="form-check form-check-radio form-check-inline" *ngFor="let ans of noOfAnswers">
              <label class="form-check-label">{{ans}}
               <input class="form-check-input" type="radio" name="{{quest}}" id="{{quest}}{{type}}" value="{{ans}}"  (change)="getAnswers({{quest}}{{type}})"> 
              <span class="form-check-sign"></span>
             </label>
            </div>
          </div>
      </form>
© www.soinside.com 2019 - 2024. All rights reserved.