Angular 如何在某些时候调用一次方法?
我的DOM结构如下:Angular 如何在某些时候调用一次方法?,angular,angular7,angular8,Angular,Angular7,Angular8,我的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)) }">&l
<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)
的值附加到cols
数组中numberReturn
中的每个对象上,并通过键进行访问,例如,您的numberReturn
看起来像
numberReturn(cols){
var retVal=[];//array your return here
retVal.forEach((item,index)=>{
item['matrixVal']=this.getMatrix(this.r,index);
})
}
然后在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>
您的问题不清楚
<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>