使用Angular我创建了以下HTML:
<ng-container *ngFor="let question of questions.questions; let i = index">
<div *ngIf="i == counter">
<button *ngFor="let item of question | keyvalue; let buttonIndex = index" class="btn btn-lg btn-primary surveyButton" type="button" value={{item.value}} (tap)="makeSelection(item.value)">
{{item.value}}
<span>
{{prevSelection + buttonIndex}}
</span>
</button>
</div>
</ng-container>
我有全局变量prevSelection1
,prevSelection2
,prevSelection3
和prevSelection4
。
我希望使用{{prevSelection + buttonIndex}}
显示所有这些变量,但是插值内的级联不起作用。
我该如何解决?
答案 0 :(得分:0)
You can create object and the try to use it.
selection = {
prevSelection1 :'abc',
prevSelection2 :'def',
prevSelection3 :'pqr',
prevSelection4 :'xyz',
}
<ng-container *ngFor="let question of questions.questions; let i = index">
<div *ngIf="i == counter">
<button *ngFor="let item of question | keyvalue; let buttonIndex = index" class="btn btn-lg btn-primary surveyButton" type="button" value={{item.value}} (tap)="makeSelection(item.value)">
{{item.value}}
<span>
{{selection['prevSelection' + buttonIndex]}}
</span>
</button>
</div>
</ng-container>
希望这对您有用