Skip to content
Snippets Groups Projects
sroll-top.service.ts 577 B
Newer Older
import { Injectable, Inject, PLATFORM_ID } from '@angular/core';
import { Router, NavigationEnd } from '@angular/router';
import { isPlatformBrowser } from '@angular/common';

@Injectable()
export class ScrollTopService {

    constructor(
Tifenn Guillas's avatar
Tifenn Guillas committed
        @Inject(PLATFORM_ID) private platformId: object, private router: Router) {
        }

        setScrollTop() {
            if (isPlatformBrowser(this.platformId)) {
                this.router.events.subscribe((event: NavigationEnd) => {
                    window.scroll(0, 0);
                });
            }
        }
    }