Angular实现实时获取当前时间

html:

ts:

export class Test{

 today:any=new Date();

 timer:any;

constructor(

) {

this.account.accountName = this.localStorageService.get('username');

this.timer=setInterval(() => {

this.today=new Date();

},1000);

}

logout() {

this.authService.logout().subscribe((data) => {

clearInterval(this.timer);//销毁

});

}

}

你可能感兴趣的:(angular实时获取时间)