Skip to content
Snippets Groups Projects
Commit 1a9bd9d6 authored by Hugo SUBTIL's avatar Hugo SUBTIL
Browse files

fix(news): fix scroll position when going on an article page

parent b662ca0d
No related branches found
No related tags found
1 merge request!187Dev
import { Component, OnInit } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
import { ActivatedRoute, Router } from '@angular/router';
import { ActivatedRoute } from '@angular/router';
import { RouterListenerService } from '../../../services/routerListener.service';
import { Post } from '../../models/post.model';
import { PostService } from '../../services/post.service';
......@@ -11,15 +11,17 @@ import { PostService } from '../../services/post.service';
styleUrls: ['./post-details.component.scss'],
})
export class PostDetailsComponent implements OnInit {
public post: Post;
constructor(
private activatedRoute: ActivatedRoute,
private router: Router,
private postService: PostService,
private sanitizer: DomSanitizer,
private routerListener: RouterListenerService
) {}
post: Post;
ngOnInit(): void {
this.resetScroll();
if (history.state.data) {
this.post = new Post(history.state.data);
this.post.safeHtml = this.sanitizer.bypassSecurityTrustHtml(this.post.html);
......@@ -35,4 +37,10 @@ export class PostDetailsComponent implements OnInit {
public backToPosts(): void {
this.routerListener.goToPreviousUrl();
}
private resetScroll(): void {
if (window.scrollY) {
window.scroll(0, 0); // reset the scroll position to the top left of the document.
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment