Refresh a page in AngularJS with only a single click

I am currently working with angularjs and I am trying to figure out how to refresh the page only once when it loads. Here is what I have attempted so far:

<script>
app.cp.register('userProfileController', function ($window) {
    debugger;
    function reload() {
        $window.location.reload();
    }
    reload();
});

However, when using this method, the page ends up refreshing multiple times instead of just once. What could be causing this issue?

Answer â„–1

After a page refresh, all data is cleared and you have to re-register your controller and run reload(), so the process will repeat.

To maintain data between page reloads, you can utilize ngStorage:

app.cp.register('userProfileController', function ($window, $localStorage) {
  debugger;
  function reload() {
    $localStorage.hasReloaded = true;
    $window.location.reload();
  }
  if (!$localStorage.hasReloaded) reload();
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What could be the reason for the malfunction of Twitter Bootstrap's typeahead feature in this case?

Struggling to implement typeahead.js into my current project. Despite having bootstrap loaded, the source code does not mention anything about typeahead. As a result, I included the standalone js file with hopes of making it work. Upon implementation, the ...

Tips for customizing font color on Google Maps Marker Clusterer

Is there a way to adjust the font color of a markerclusterer marker? Below is my current code for customizing the marker's style: mcOptions = {styles: [{ height: 27, url: "image.png", width: 35 ...

Can you recommend a basic, invertible, non-secure string cipher function that performs exceptionally well in terms of data dispersal?

I am in need of creating two functions to obscure and reveal a string, following the structure below: string encrypt(string originalText, string key) string decrypt(string scrambledText, string key) I require these functions to be concise and easy t ...

Parent passing down React state, but child component fails to update it

When a setState function is passed down from a parent component, I aim to update the state of the parent setter if the enter key is pressed. However, despite setting the state, nothing seems to happen and I am left with an empty array. Below is the snippe ...

Unable to utilize the forEach() function on an array-like object

While I generally know how to use forEach, I recently encountered a situation that left me puzzled. Even after searching online, I couldn't find any new information that could help. I recently started delving into TypeScript due to my work with Angul ...

What steps should be taken to activate eslint caching?

I'm attempting to activate eslint caching by following the instructions in this section of the user guide The command I am using is npm run lint -- --cache=true, and the lint script simply executes a script that spawns esw (which itself runs eslint â ...

I want to display events from my database table on their corresponding dates using JavaScript and jQuery. How can I achieve this?

Using the FullCalendar plugin, I attempted to achieve a specific functionality, but unfortunately fell short of my goal. Below is the snippet of my scripting code: $('#calendar').fullCalendar({ //theme: true, header: { ...

Implementing interactive dropdown menus to trigger specific actions

I have modified some code I found in a tutorial on creating hoverable dropdowns from W3. Instead of the default behavior where clicking on a link takes you to another page, I want to pass a value to a function when a user clicks. Below is a snippet of the ...

Error in TypeScript: The property 'data' is not found within type '{ children?: ReactNode; }'. (ts2339)

Question I am currently working on a project using BlitzJS. While fetching some data, I encountered a Typescript issue that says: Property 'data' does not exist on type '{ children?: ReactNode; }'.ts(2339) import { BlitzPage } from &q ...

What is the reason why Prettier does not automatically format code in Visual Studio Code?

After installing and enabling ESLint and Prettier in my Nuxt application, I made the switch to Visual Studio Code. However, when I open a .vue file and use CMD+ Shift + P to select Format Document, my file remains unformatted. I even have the Prettier ex ...

Toggle the class and execute the order within a jQuery script

When the mouse moves in, the jQuery trigger enters the status. $(".test").bind("mouseenter mouseout", function(event) { $(this).toggleClass("entered"); alert("mouse position (" + event.pageX + "," + event.pageY + ")"); }); .entered { ...

Leveraging Angular to dynamically adjust the height of ng-if child elements based on parent

I'm struggling with a few things in my current setup. I have a view that consists of 3 states - intro, loading, and completed. My goal is to create a sliding animation from left to right as the user moves through these states. Here is the basic struc ...

Can you explain the "parameters" in the Function link such as scope, element, and attrs in AngularJS?

After diving into AngularJS for a few months, I've searched high and low on the web and in my AngularJS Directives guidebook to solve this mystery. Every time I come across directives, I see this particular block of code: link: function(scope, eleme ...

The PHP AJAX call is returning an undefined response status

I'm facing two issues here. The first problem is that when I try to access response.status, it returns undefined. The second issue is related to the creation of "$_SESSION['promo-code'] = $arr". When I enter a promo code, I encounter the fol ...

Using the map function twice in React Native causes a rendering issue

<View style={styles.card} > {store.crud.list.map(function(element, index){ return ( <View style={styles.wrapper}> {element.map(function(number, index){ return( ...

Is it possible to create an input field exclusively for tags using only CSS?

I am currently facing some limitations with a website I am managing. Unfortunately, I do not have the ability to incorporate additional libraries such as custom jQuery or JavaScript scripts. My goal is to customize an input field for tags so that when us ...

Fade out the notification div using jQuery in MVC4

I'm a beginner in the world of JavaScript and JQuery and I could really use some assistance with resolving a simple issue that I've encountered. As part of my application's functionality, I am dynamically loading the following div based on ...

Experimenting with axios.create() instance using jest

I have attempted multiple solutions for this task. I am trying to test an axios instance API call without using any libraries like jest-axios-mock, moaxios, or msw. I believe it is possible, as I have successfully tested simple axios calls (axios.get / axi ...

Tips for streamlining a conditional statement with three parameters

Looking to streamline this function with binary inputs: export const handleStepCompletion = (userSave: number, concur: number, signature: number) => { if (userSave === 0 && concur === 0 && signature === 0) { return {complet ...

Learn the process of eliminating a class utilizing this JavaScript function

This script is designed to identify and manipulate elements with the class menu-option-set. When an element within this class is clicked, it adds the class "selected" to that specific element while removing it from all others in the list. My goal is to en ...