Last active
June 2, 2022 00:59
-
-
Save muhammadadilmalik/52fa872076cec56d7e3a773ede1f42d7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="row" style="margin-bottom: 12px;"> | |
<div class="col-md-12" style="text-align: center;"> | |
This page will refresh in <div class="time">{{minutes}}</div> Min <div class="time">{{seconds}}</div> Sec | |
</div> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.time { | |
background-color: #FC5B2D; | |
color: white; | |
width: 25px; | |
height: 20px; | |
display: inline-block; | |
border-radius: 5px; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit, Output, Input, EventEmitter, ChangeDetectorRef } from '@angular/core'; | |
import { Subscription, Observable, timer } from 'rxjs'; | |
import * as moment from 'moment'; | |
@Component({ | |
selector: 'kt-auto-refresh', | |
templateUrl: './auto-refresh.component.html', | |
styleUrls: ['./auto-refresh.component.scss'] | |
}) | |
export class AutoRefreshComponent implements OnInit { | |
private subscription: Subscription; | |
@Output() TimerExpired: EventEmitter<any> = new EventEmitter<any>(); | |
@Input() SearchDate: moment.Moment = moment(); | |
@Input() ElapsTime: number = 3; | |
searchEndDate: moment.Moment; | |
remainingTime: number; | |
minutes: number; | |
seconds: number; | |
everySecond: Observable<number> = timer(0, 1000); | |
constructor(private ref: ChangeDetectorRef) { | |
this.searchEndDate = this.SearchDate.add(this.ElapsTime, "minutes"); | |
} | |
ngOnInit() { | |
this.subscription = this.everySecond.subscribe((seconds) => { | |
var currentTime: moment.Moment = moment(); | |
this.remainingTime = this.searchEndDate.diff(currentTime) | |
this.remainingTime = this.remainingTime / 1000; | |
if (this.remainingTime <= 0) { | |
this.SearchDate = moment(); | |
this.searchEndDate = this.SearchDate.add(this.ElapsTime, "minutes"); | |
this.TimerExpired.emit(); | |
} | |
else { | |
this.minutes = Math.floor(this.remainingTime / 60); | |
this.seconds = Math.floor(this.remainingTime - this.minutes * 60); | |
} | |
this.ref.markForCheck() | |
}) | |
} | |
ngOnDestroy(): void { | |
this.subscription.unsubscribe(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
everySecond: Observable<number> = timer(0, 1000); | |
this.subscription = this.everySecond.subscribe((seconds) => { | |
var currentTime: moment.Moment = moment(); | |
this.remainingTime = this.searchEndDate.diff(currentTime) | |
this.remainingTime = this.remainingTime / 1000; | |
if (this.remainingTime <= 0) { | |
this.SearchDate = moment(); | |
this.searchEndDate = this.SearchDate.add(this.ElapsTime, "minutes"); | |
this.TimerExpired.emit(); | |
} | |
else { | |
this.minutes = Math.floor(this.remainingTime / 60); | |
this.seconds = Math.floor(this.remainingTime - this.minutes * 60); | |
} | |
this.ref.markForCheck() | |
}) |
What is moment that you imported ?
What is moment that you imported ?
https://www.npmjs.com/package/moment (This is the package, it provides various useful functions related to date and time)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
where we have to write samplets in Visual Studio Code.