Running a JavaScript function at regular intervals in Angular with Primo

The function should be initiated every n-seconds:

 app.controller('prmServiceHeaderAfterController',[function () {
    var vm = this;     
    vm.func_name = function func_name(obt-var) {
    var timesRun = 0;
    var checkExistenceOfElement = setInterval(function () {
   // ...
    }
        }, 50);
    };
    vm.func_name();
    }]);

This function only works when the page is manually refreshed.

Answer №1

To achieve repetitive actions in JavaScript, utilize the setInterval method that requires a callback function and interval duration as parameters.

setTimeout(function() {
    //your code to run periodically
}, timeInMilliseconds);

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

Modifying an Object within a for-in loop

Hi there, I'm facing a challenge with updating an object that has child properties in my Angular application. Here is the initial object: $scope.osbStep = { test0Nav : { current : false, comp ...

Using Vue Js to trigger an HTTP request when the user has finished typing

Here is an example of an input box I am working with: <b-row> <b-col md="3" v-for="(header, index) in columns" :key="index" > <b-form-group> <b-form-input ...

Showing PDF (Blob) on iOS received from my angularjs application - A how-to guide

My Angular 1.5 app connects to a backend server running Java, Tomcat, and Spring via REST. One of the REST services generates PDF files and sends them to clients. While this works well on desktop browsers like Firefox and Chrome, I'm facing an issue ...

"Troubleshooting: Why is Angular's Equalizer from Foundation not

I'm having trouble getting Foundation Equalizer (the JS tool for equalizing div heights) to function properly. The demo is not displaying correctly. I am currently using Foundation v6.1.2 My setup includes using it in an ng-view, and in the index fi ...

Is there a way to customize the file path that is displayed when utilizing bower in a Yeoman Angular application?

My angular app is using html5mode, however, when I execute bower install with grunt, the paths are displayed as <script src="bower_components/... Is there a way to change this to <script src="/bower_components/...? I have included a <base href ...

Looking to verify an "else" condition within an alert in ReactJS?

In my code below, there is a text field and a button. If the text field is not filled and the button is submitted, an alert message should appear asking to fill in the input text. Currently, when I submit the button without filling the input text, the ale ...

Activating the Play button to start streaming a link

Recently delved into the world of Ionic 4 and Angular, so definitely a beginner :) Purchased a UI Template from code canyon but didn't realize I needed to code the music player part. Been trying to get a music stream playing but no luck. Came across ...

Angular tree dropdown menu structure

Check out this functional jsfiddle: working example for the secondary level In the jsfiddle, I am able to assign a brand from the first dropdown and a model from the second dropdown to each car created through ng-repeat. It is all working smoothly. Howev ...

The dropdown items in the Tailwind menu fail to pop out from the React Next.js card component

My dropdown menu component, called DropdownWithSearch, is encountering an issue where it opens inside the card component (UserAssignForm) instead of popping out as expected. You can view the problem here. The DropdownWithSearch component import { Menu, Tr ...

Having trouble with a straightforward Angular directive that uses restrict to 'C' and won't function as expected

I am currently working on a straightforward directive, and here is the app.js code: var myApp = angular.module('myApp', []) myApp.directive('layout-top', function() { return { restrict: 'C', templateUrl: ...

Get the characters from a JavaScript string, but make sure to exclude

There is a text string that I need to work with: TEST:ABCDEGF:18:32 This text includes letters and numbers, but I want to extract all of them excluding the : character. Previously, I was using the following code successfully: lines.split(":"); However ...

An improved method for verifying a JSON value that works seamlessly across different web browsers

I've encountered a scenario while working with an API where a value is stored as a string variable in the following format: var majorValue = "some_major_name"; To determine which HTML content to load based on this string value, I created a ...

Having difficulty extracting only names from the database with mongoose

My goal is to retrieve the value of all the name keys stored in my database. Each document in the database has only one key, which is the "name" key. Below is the code snippet that I need assistance with: user.find({}, 'name', function(err, user ...

Emphasize the error message "Cannot find name" or "any" within the Vs Code

When using VS Code, I've noticed that when I make a mistake in Typescript it highlights the error as "Cannot find name" / any, while in Javascript it simply assigns "any" without highlighting. Here's an image for reference: https://i.sstatic.net/ ...

When a function is called, retrieve a specific number of elements from an array using the slice method in

If I have an array of 15 objects, but I am only displaying 5 on the browser using this code: const displayedArray = array.slice(0,4) I also have a function that will load another 5 objects each time a user scrolls down. displayedArray.concat(array.slice ...

Eslint in VS Code encounters issues resolving paths within a monorepo

I'm currently working on a project with the following structure: modules │ ├── client │ ├── .eslintrc.json │ └── backend │ ├── .eslintrc.json ... One issue I've run into is that when I access the p ...

What could be the reason for the failure of my class isInstance() check

Do you see any issues with the object being an instance of ChatRoom? Let me know your thoughts. Class: export class ChatRoom { public id?: number; public name_of_chat_room: string; public chat_creator_user_id: number; public chat_room_is_active: 0 ...

What could be causing the additional iteration in my for loop and preventing it from copying to the intended cells?

Every time I execute my script, it seems to run one additional time than necessary. For instance, it generates a PDF and marks a cell as processed below the last row. Another issue is that the URLs do not align correctly with their corresponding names. I ...

Changing the default view in Ionic

I'm facing a simple issue that I can't seem to solve. I've set up a blank project in Ionic and I want to make a default home screen the first view that loads. However, all I see is a blank screen when I run it in the browser. Here's my ...

Error: Attempting to access property '7' of an undefined value

I am currently working on a code that checks if the checkboxes for CEO_box and Acc_box are checked. If they are, an email is sent to the corresponding email address in the column, and the inform_cell is set as 'informed'. However, I keep encounte ...