angular4定时器定时替换图片--利用递归类似方法

import { Component, OnInit } from '@angular/core';

@ Component({
selector: 'indicator',
templateUrl: './indicator.component.html',
styleUrls: [ './indicator.component.css']
})
export class IndicatorComponent implements OnInit {
public imgUrl;
public t;
public i;
constructor() { }

ngOnInit() {
//图片集合
this. t = new Array( "../assets/images/bg.png", "../assets/images/hls.jpg", "../assets/images/zky.jpg");
this. i = 0;

this. changepic();
}

//循环方法
changepic() {
if ( this. i > 2)
this. i = 0;

this. imgUrl = this. t[ this. i];
this. i++;
setTimeout(() => {
this. changepic()
}, 1000);
}
}

猜你喜欢

转载自blog.csdn.net/qq_34790644/article/details/80337113