Я создаю HTML-шаблон внутри цикла for, я хотел бы передать значение переменной в шаблон и создать динамические шаблоны.
Ниже мой цикл for, мне нужно значение colIndex, которое должно быть передано в теге Span HTML, упомянутом как "Need colIndex здесь",
for (var colIndex = 0; colIndex < colCount; colIndex++) {
$scope.gridOptions.columnDefs.push({
name: 'col-' + colIndex,
aggregationType: uiGridConstants.aggregationTypes.sum,
width: 85,
treeAggregationType: uiGridTreeViewConstants.aggregation.SUM,
cellTemplate: '<div class="ui-grid-cell-contents">'+
'<span ng-if="!(row.entity[\'$$\' + col.uid])">{{row.entity[\'col-'+'<<Need colIndex here>>'+'\'] CUSTOM_FILTERS}}</span>'+
'<span ng-if="row.entity[\'$$\' + col.uid]"> {{row.entity["$$" + col.uid].value CUSTOM_FILTERS}}</span>'+
'</div>'
});
}
Пожалуйста, предложите.
Вы можете сделать это,
for (var colIndex = 0; colIndex < colCount; colIndex++) {
$scope.gridOptions.columnDefs.push({
name: 'col-' + colIndex,
aggregationType: uiGridConstants.aggregationTypes.sum,
width: 85,
treeAggregationType: uiGridTreeViewConstants.aggregation.SUM,
cellTemplate: '<div class="ui-grid-cell-contents">'+
'<span ng-if="!(row.entity[\'$$\' + col.uid])">{{row.entity[\'col-'+colIndex+'\'] CUSTOM_FILTERS}}</span>'+
'<span ng-if="row.entity[\'$$\' + col.uid]"> {{row.entity["$$" + col.uid].value CUSTOM_FILTERS}}</span>'+
'</div>'
});
}
name
?