如何一次调用方法?

问题描述 投票:0回答:1

我有以下角度的结构DOM:

<div
      class="column"
      *ngFor="let cols of numberReturn(cols); let c = index"
      (click)="select(getMatrix(r, c))"
      title="{{ getMatrix(r, c).title }}"
      [ngClass]="{ active: isToolSelected(getMatrix(r, c)) }"></div>

如您所见,我有时会称呼getMatrix(r, c)

如何调用一次并将结果传递到任何地方,例如:

let r = getMatrix(r, c);
(click)="select(r)"
title="{{ r.title }}"
angular angular7 angular8
1个回答
0
投票

您可以将getMatrix(r, c)的值附加到cols内的numberReturn数组的每个对象中,并通过键进行访问,例如numberReturn看起来像]

numberReturn(cols){
var retVal=[];//array your return here
retVal.forEach((item,index)=>{
item['matrixVal']=this.getMatrix(this.r,index);
})
}

then on ui

<div
      class="column"
      *ngFor="let cols of numberReturn(cols); let c = index"
      (click)="select(cols.matrixVal)"
      title="{{ cols.matrixVal.title }}"
      [ngClass]="{ active: isToolSelected(cols.matrixVal) }"></div>
© www.soinside.com 2019 - 2024. All rights reserved.