Last active
September 26, 2022 06:12
-
-
Save uzbekdev1/ab651fdd66a240ed27f80ffe7988218a to your computer and use it in GitHub Desktop.
Angular refreshing version
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
{ | |
"assets":[ | |
"src/config.json " | |
] | |
} |
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
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(); | |
}); | |
} | |
} |
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
{ | |
version:"1.9" | |
} |
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
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