2016-11-24 81 views
0

我通过ng-repeat动态创建materializecss复选框。问题是,在实现,所述“关于”复选框标签上必须与该ID对input这样对应:动态生成materializecss复选框

<div class="checkbox-patient-info-medical"> 
    <input type="checkbox" id="medical-checkbox"> 
    <label for="medical-checkbox"> Prior Authorization Required*</label> 
</div> 

我生成与NG-重复场,且有1个文本框用于每个所产生的一套领域。代码如下:

<div class="medical-insurance-holder" ng-repeat="person in vm.myData[0].medicalInsuranceContainer track by $index"> 
    <p class="patient-info-holder-text"> 
    RELATIONSHIP TO PATIENT:&nbsp&nbsp&nbsp<b>{{person.relationshipToPatient}}</b> 
    </p> 
    <p class="patient-info-holder-text"> 
    GROUP NUMBER:&nbsp&nbsp&nbsp<b>{{person.groupNum}}</b> 
    </p> 
    <p class="patient-info-holder-text"> 
    SUBSCRIBER D.O.B:&nbsp&nbsp&nbsp<b>{{person.subscriberDob}}</b> 
    </p> 
    <div class="checkbox-patient-info-medical"> 
    <input type="checkbox" id="medical-checkbox"><label for="medical-checkbox"> Prior Authorization Required*</label> 
    </div> 
</div> 

我怎样才能改变这些复选框的label forid为NG-重复创建它们?如果我保持原样,我只能点击创建的第一个复选框。

<div class="checkbox-patient-info-medical"> 
    <input type="checkbox" id="medical-checkbox{{$index}}"> 
    <label for="medical-checkbox{{$index}}"> Prior Authorization Required*</label> 
</div> 

检查小提琴:

感谢

回答

0

我们需要输入和标签要使用AngularJS动态地为materializecss生成复选框。使用下面的代码动态生成复选框。

 <tbody> 
     <tr ng-repeat="x in data"> 
     <td>{{x.name}}</td> 
     <td>{{x.phone}}</td> 
     <td> 
     <input type="checkbox" id="cbox{{$index}}" /> 
     <label for="cbox{{$index}}"></label> 
     </td> 
     </tr> 
    </tbody> 

如果您没有使用for的标签,那么您将无法获得复选框。

这里CBOX会产生像cbox1,cbox2,cbox3 IDS ..... cboxn