Skip to content

Instantly share code, notes, and snippets.

@uzbekdev1
Last active September 26, 2022 06:12
Show Gist options
  • Save uzbekdev1/ab651fdd66a240ed27f80ffe7988218a to your computer and use it in GitHub Desktop.
Save uzbekdev1/ab651fdd66a240ed27f80ffe7988218a to your computer and use it in GitHub Desktop.
Angular refreshing version
{
"assets":[
"src/config.json "
]
}
export class AppComponent {
constructor(private version: VersionService, private router: Router) {
router.events.pipe(filter((e: Event): e is NavigationEnd => e instanceof NavigationEnd)).subscribe((e: NavigationEnd) => {
this.version.checkApp();
});
}
}
{
version:"1.9"
}
export class VersionService {
constructor(private http: HttpClient) {}
checkApp(): void {
const currentVersion = localStorage.getItem("version");
this.fetchConfig().subscribe(response => {
const newVersion = response['version'];
if (!currentVersion) {
localStorage.setItem("version", newVersion);
} else {
if (newVersion != currentVersion) {
localStorage.setItem("version", newVersion);
location.reload();
}
}
});
}
private fetchConfig(): Observable<any> {
const timeNow = new Date().getTime();
const appSite = `${environment.appSite}/config.json?v=${timeNow}`;
return this.http.get(appSite);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment