What is the best way to repeatedly execute a function upon button click?

for (let index = 0; index < shoppingCenters.length; index++) {
  const mall = shoppingCenters[index];
  locateAddress(mall);
}

$scope.locateAddress = function(mall) {}

XHTML

<ion-nav-buttons side="primary">
  <button class="button" ng-click="locateAddress()">
    Find My Location
  </button>
</ion-nav-buttons>

<div id="map-container" data-tap-disabled="true"></div>

Hello, I am encountering an issue where I receive the following message when calling a function within my loop: ReferenceError: locateAddress is not defined.

Answer №1

Don't forget to include the $scope:

$scope.codeAddress = function(mall){} // make sure to add this function before the loop

for (var i = 0; i < malls.length; i++) {
     mall = malls[i];
     $scope.codeAddress(mall);
}

Check out this JSFIDDLE example.

Answer №2

One way to repeatedly call a function with a time interval in JavaScript is by using setInterval.

var count = 0;
 var int = setInterval(function(){
// do your task here
FunctionYouWantToRepeat()
count++;
if(count === 10) {
    clearInterval(int);
}
}, 200);

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

Generating a new Blob through assembling MediaRecorder blob sections leads to a blank Blob

I’ve encountered a peculiar issue with the new Blob constructor. My code returns an array of Blobs from the MediaRecorder: However, when trying to work with this blob in my code, calling new Blob(audioChunks) results in an empty array being outputted. S ...

Creating interactive network visualizations using JavaScript

I've been in search of javascript code that can help me create a visual representation similar to this example. Specifically, I need something that can display links between boxes when clicked on or hovered over. I'm still not sure what this par ...

Make sure to use jQuery waterfall 'reflow' only once all the images have finished loading

Currently, I am utilizing jQuery waterfall to achieve a grid-style display on my website. To address the issue of images overlapping, I have enclosed the waterfall method within a .load() function like this: $(window).load(function(){ $('#buildcon ...

A guide on traversing a HTML table and cycling through its contents with JavaScript

I'm currently in the process of constructing a grid with 20 rows and 20 columns of squares, but I am encountering difficulties with looping through table values to effectively create the grid. For more detailed information on the html code, please se ...

The preflight request's response failed to meet the access control criteria due to the absence of the 'Access-Control-Allow-Origin' header

I encountered an issue while using ngResource to call a REST API hosted on Amazon Web Services: Upon making the request to , I received the following error message: "XMLHttpRequest cannot load. Response to preflight request doesn't pass access cont ...

Use a personalized CSS class with the Kendo Dropdown Widget

Is there a way to assign a custom CSS class to the dropdown HTML container that is created when using the .kendoDropDownList() method on a <select> or <input> element? In this fiddle ( http://jsfiddle.net/lav911/n9V4N/ ) you can see the releva ...

Leverage OpenID Connect in Azure Active Directory with authentication code flow

Currently, I am developing an authentication system for a NodeJS and Express web application that requires users to be directed to Microsoft SSO. To achieve this, I am utilizing passport-azure-ad and OpenID Connect. My main query is - Is it mandatory to ...

Determine in React whether a JSX Element is a descendant of a specific class

I am currently working with TypeScript and need to determine if a JSX.Element instance is a subclass of another React component. For instance, if I have a Vehicle component and a Car component that extends it, then when given a JSX.Element generated from ...

Issue with Vue directive bind not functioning after element refresh

My approach involves utilizing vue.js to create forms, where all fields are structured within a JavaScript objects array. Here is an example of the structure I use: { type: "input", mask: "date", default: "2018/04/14" }, { type: "input", ...

Anomaly in the default checked state of checkboxes

I'm currently working on a project and encountering an issue with the code below. I need to incorporate a forEach() loop within getElements() instead of using map(). Additionally, I want the default state of a checkbox to remain checked even after nav ...

React - what propType should be used for the Material UI icon?

I am planning to send a Material-UI icon to the Test component and I need to define the correct proptype for it. App.js import "./styles.css"; import VisibilityIcon from "@material-ui/icons/Visibility"; import Test from "./Test&q ...

"Exploring the Synchronization Feature in Vue.js 2.3 with Element UI Dialog Components

Recently, I've encountered some changes while using Element UI with the latest release of Vue.js 2.3 In my project, a dialog should only be displayed if certain conditions are met: private.userCanManageUsers && private.pendingUsers.length > ...

Ways to rearrange div elements using JavaScript

I need assistance with reordering div elements using JavaScript, as I am unsure of how to accomplish this task. Specifically, I have two divs implemented in HTML, and I would like the div with id="navigation" to appear after the div with class="row subhea ...

Angular: attaching an identification number to an API endpoint

I encountered a problem that has left me puzzled: I am attempting to remove a row from a table by passing the ID of that row (known as the record) through the path of my API. However, for some reason it is not being recognized. Strangely enough, when I sub ...

Turn off javascript on a website that you are embedding into another site

Is it feasible to deactivate JavaScript on a website you are attempting to embed? If the website is working against your embedding efforts, could you effectively neutralize all their JavaScript, even if it requires users to engage with the site without J ...

Issue with Vue.js input not updating with v-model after input sanitization in watch handler

Recently, while working with Vue 2.6, I came across an unusual issue when trying to sanitize user input. The main culprit seemed to be a custom component that housed the input field. Here's a simplified version of it: <template> <input :na ...

AngularJS: Iterating through all isolated scope directive templates and performing a click event on one of them

Here is the HTML code I am working with: <div ng-repeat="mydata in data" class="ng-scope ng-binding"> <p class="ng-binding">{{mydata.postdata}}</p> <div my-rating rating-value="rating" data-cat="post" data-id="mydata.id" >& ...

Challenge with SSRS report's cross-origin problem

I am currently facing a challenge while integrating an SSRS report into my Angular application. Below is the code snippet I am working with: Template: <div panel-charts style="width:100%:height:100%" </div> Directive: a ...

Switching between different elements in an array using React

I've got a collection of appointments and I need to create a React view that will show them one by one. Users should be able to navigate through the appointments using arrow buttons. Here's an example of what the data looks like: const arr = [ ...

what is the method to incorporate an array of objects in a schemaless mongoose database?

**model schema** var mongoose = require('mongoose'); var Schema = mongoose.Schema; var itemSchema = new Schema({ name: {type: String, required: true}, price: {type: String} }); var objectSchema = new Schema({ name: {type: String, req ...