#How to refresh a page for only one time?

10 messages · Page 1 of 1 (latest)

still saddle
#

i wanted the page to reload if there is no data in the api

ngOnInit(): void {
    this.activatedRoute.queryParams.subscribe((params: any) => {
      this.fill = params.data;
      params = {
        keyword: this.fill
      }
      this.jobService.searchJobs(params).subscribe(
        (response: any) => {
          this.jobSearchModel.recentJobs = response.data;
        },
        (error) => {
          window.location.reload();
        })
    })
  }

i've tried this but the page keep reloading forever, how can i refresh the page only for one time?

#

oh i've found it

cold tundra
#

you can set a value in the session storage and check if the value exists or not.
But are sure you want to reload the page? why do you want to do that? what is your goal?

still saddle
#

i think problem is solved

#

thanks elia

cold tundra
#

ok good 👍
FYI avoid reloading the page if it's not absolutely necessary. It's poor UX

still saddle
#

okayy 😀 thanks

modest scroll
#

If you need a subscribe in a subscribe, it means u need mergeMap, switchMap, concatMap or exhaustMap:

ngOnInit(): void {
    this.activatedRoute.queryParams.pipe(
      switchMap(params => this.jobService.searchJobs({keyword: params.data}))
    ).subscribe((response: any) => {
        this.jobSearchModel.recentJobs = response.data;
      },
      (error) => {
        window.location.reload();
      }))
  }
#

Unrelated to the question at hand, but wanted to share it incase its helpful.