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

你可能感兴趣的:(angular4,前端问题)