我是Angular的新手,我想使用setInterval
函数来计数,但是我不能成功。有人能帮我吗?(我很抱歉我的英语水平很差。)提前感谢。
这里是我的success-facts.component.ts
import {Component} from '@angular/core';
@Component({
selector: 'app-success-facts',
templateUrl: './success-facts.component.html',
styleUrls: ['./success-facts.component.css']
})
export class SuccessFactsComponent {
startValue: number = 0;
countNumber: any = setInterval(() => {});
projectCountStop: any = setInterval( () => {
this.countNumber++;
if(this.countNumber === 20 ) {
clearInterval(this.projectCountStop)
}
}, 10 )
public successCounterData: any[] = [
{
id: 0,
countNumber: setInterval(() => {
this.startValue++;
if(this.startValue == 2) {
clearInterval() // I don't know what should I use for parameter here, I should use "countNumber" but I can't use
}
},10),
text: 'Project Complete',
isRate: false,
},
{
id: 1,
countNumber: 5000,
text: 'Happy Clients',
isRate: false,
},
{
id: 2,
countNumber: 25,
text: 'Years Experience',
isRate: false
},
{
id: 3,
countNumber: 90,
text: 'Success Rate',
isRate: true
},
{
id: 4,
countNumber: 35,
text: 'Expert Advisors',
isRate: false
}
]
}
这里是我的success-facts.component.html
<div *ngFor="let count of successCounterData" class="count-column">
<div class="inner-box count-box">
<div class="count-outer">
<span *ngIf="count.isRate; else elseBlock" class="count-text">{{ count.countNumber }}%</span>
<ng-template #elseBlock>{{startValue}}</ng-template>
</div>
<h4 class="counter-title">{{ count.text }}</h4>
</div>
</div>
我尝试使用setInterval
函数与clearInternal
函数,但我不知道如何在数组中使用它,至少我不知道我应该在clearInterval
函数中写什么参数
{
id: 0,
countNumber: setInterval(() => {
this.startValue++;
if(this.startValue == 2) {
clearInterval()
}
},10),
text: 'Project Complete',
isRate: false,
},
我想增加没有按钮或没有点击事件的数量
1条答案
按热度按时间kpbwa7wx1#
我用OnInit解决了这个问题,如果有人有同样的问题,这里是解决方案;
success-facts.component.html
成功-事实.组件.ts