How to refresh the screen in the Angular?

0

Look at the code below;

import { Location } from '@angular/common';
@Component({
  selector: 'app-node-paginate',
  templateUrl: './node-paginate.component.html',
  styleUrls: ['./node-paginate.component.css']
})
export class NodePaginateComponent implements OnInit {
  constructor(private location: Location) {}

  ngOnInit() {
      this.load();
  }

  load() {
      location.reload()
    }

This code above refreshes the screen uninterruptedly, but what I really need is for it to refresh.

My goal is when the user accesses the page, the page can perform a screen refresh, but it needs to be only a refresh and not several as is happening today.

At the request of Guilherme Costamilam

This is a problem I'm having too;  

I'musingversion6ofAngular.

Ialsotriedthiswaytoknowwhatcameoutintheconsole.log;

import{Component,OnInit,HostListener}from'@angular/core';import{Location}from'@angular/common';@Component({selector:'app-node-paginate',templateUrl:'./node-paginate.component.html',styleUrls:['./node-paginate.component.css']})exportclassNodePaginateComponentimplementsOnInit{publicinnerWidth:any;constructor(privatelocation:Location){}ngOnInit(){this.innerWidth=window.innerWidth;console.log(this.innerWidth);this.load();}load(){console.log(sessionStorage);//Sessionstoragesalvaosdadoscomostring(sessionStorage.refresh=='true'||!sessionStorage.refresh)&&location.reload();sessionStorage.refresh=false;}@HostListener('window:resize',['$event'])onResize(event){this.innerWidth=window.innerWidth;}}

AndIhadthisresult;

But I do not understand why you are not recognizing the variable refresh

    
asked by anonymous 05.09.2018 / 17:08

1 answer

0

In a simple way, save to session / local storage if it has already been reloaded and use it as conditional to load again:

ngOnInit() {
  this.load();
}

load() {
  //Session storage salva os dados como string
  (sessionStorage.refresh == 'true' || !sessionStorage.refresh) && location.reload();
  sessionStorage.refresh = false;
}
You can also have a variable in the url that defines this, but instead of just reloading it would have to redirect to another url, for example, dominio.com/foo/true/ reload, dominio.com/foo/false/ or dominio.com/foo will not reload, then in your component you check the value of the variable in url instead of session / local storage

    
05.09.2018 / 17:38