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);
}
}

阅读更多
想对作者说点什么?
相关热词

博主推荐

换一批

没有更多推荐了,返回首页