我想使用* ngFor并重复我的数组元素myltiple次。像这样:
在组件中:
mesViv = ((fech_act//10000)%100) - ((fec_nac//10000)%100)
mesViv = ((25072017//10000)%100) - ((11101982//10000)%100)
mesViv = (2507%100) - (1110%100)
mesViv = (7) - (10)
mesViv = -3
在模板中:
import datetime
def numerical_date_to_date(dtint):
# Factor out conversion from weird int-based format to datetime.date
daymon, years = divmod(dtint, 10000)
days, months = divmod(daymon, 100)
return datetime.date(years, months, days)
def min_vivido(fech_act, fec_nac):
diff = numerical_date_to_date(fech_act) - numerical_date_to_date(fec_nac)
horas_dias = diff.days * 24
min_dias = horas_dias * 60
return min_dias, horas_dias, diff.days
我想在渲染中看到类似的东西:
a,b,c,d,e
点击' a':
d,e,a,b,c
点击' e':
c,d,e,a,b
有什么想法吗? :) 谢谢你的帮助!
答案 0 :(得分:1)
试试这会解决您的问题
<div *ngFor="let letter of letters" (click)="myMethod(letter)">{{letter}}
</div>
myMethod(selectedLetter){
let postLen = 3; // configurable
let i=0, len =str1.length;
let foundFlag = false;
let arr1 = [], arr2 = [], arr3 = [];
for(;i<len;i++){
if(str1[i] == selectedLetter){
for(k=0;k<postLen && (i+k)< len ; k++){
arr1.push(str1[i+k]);
i++;
}
foundFlag = true;
}else if(!foundFlag){
arr2.push(str1[i]);
}else{
arr3.push(str1[i]);
}
}
this.letters = arr3.concat(arr2);
this.letters = this.letters.concat(arr1);
}
答案 1 :(得分:0)
只需使用ngIf
的两个列表:第一个列表会在currentLetter
或currentLetter
之前呈现字母,而第二个列表会在currentLetter
之后呈现字母。
<ng-container *ngFor="let letter of letters; index as i">
<button *ngIf="i>=letters.indexOf(currentLetter)" (click)="currentLetter = letter">{{letter}}</button>
</ng-container>
<ng-container *ngFor="let letter of letters; index as i">
<button *ngIf="i<letters.indexOf(currentLetter)" (click)="currentLetter = letter">{{letter}}</button>
</ng-container>