我需要在ngFor循环中创建唯一的锚点名称/组件,以将其与ComponentResolver.resolveComponent一起使用.
@H_404_18@<div> <table> <tr *ng-for="#vIndex of vArr"> <td *ng-for="#hIndex of hArr"> <div #uniqueanchorname{{vIndex}}_{{hIndex}}></div> </td> </tr> </table> </div>
生成的HTML应该看起来像这样:
<div> <table> <tr> <td> <div #uniqueanchorname0_0></div> </td> <td> <div #uniqueanchorname0_1></div> </td> </tr> <tr> <td> <div #uniqueanchorname1_0></div> </td> <td> <div #uniqueanchorname1_1></div> </td> <td> <div #uniqueanchorname1_2></div> </td> </tr> </table> </div>
有了它,我可以使用DynamicComponentLoader,如:
loader.loadIntoLocation(responseDependentComponent,elementRef,'uniqueAnchorName1_2');
生成的HTML不会被替换,看起来像:
<div> <table> <tr> <td> <div #uniqueanchorname{{vIndex}}_{{hIndex}}></div> </td> <td> <div #uniqueanchorname{{vIndex}}_{{hIndex}}></div> </td> </tr> <tr> <td> <div #uniqueanchorname{{vIndex}}_{{hIndex}}></div> </td> <td> <div #uniqueanchorname{{vIndex}}_{{hIndex}}></div> </td> <td> <div #uniqueanchorname{{vIndex}}_{{hIndex}}></div> </td> </tr> </table> </div>