Global Variables Evolution as Variables are Assigned

So I'm encountering an issue where running a function and assigning variables to the data seems to be updating my global every time. I've double-checked my code, but I can't seem to pinpoint where the update to the global is coming from. Am I overlooking something?

var newInputs = $scope.configurationMap['RDY2000'].configuration.inputs.universalOffsets;
$scope.rdyInputs = function(){

    var input = [];

    for (var x = 0; x < newInputs.length; x++) {
        if (newInputs[x].sensorType) {
            input.push(newInputs[x])
        }
    }   
    return input
}

if($scope.data.property = 'rdy2000'){
    $scope.inputs = $scope.rdyInputs($scope.data);
    var Test = configUtilService.getOnlyCts(inputsKeyList)
    var counter = Test.length + 1;
    var tether = $scope.originalData.tether[0];

    for (var x = 0; x < $scope.inputs.length; x++) {
        $scope.data.inputs[x] = $scope.inputs[x]
        $scope.data.inputs[x].key = 'CT' + counter;
        $scope.data.inputs[x].type = 'ct';
        $scope.data.inputs[x].description = tether +  $scope.inputs[x].description;
        counter++;
    }
}

Answer №1

It is possible that the function rdyInputs might require an additional parameter:

$scope.rdyInputs = function(newInputs){

    var input = [];

    for (var x = 0; x < newInputs.length; x++) {
        if (newInputs[x].sensorType) {
            input.push(newInputs[x])
        }
    }   
    return input;
}

Avoid using global variables; instead, pass the required information as a parameter.

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

Creating a static Top Bar that remains unaffected by page refreshing using Ajax or any other method can be achieved by implementing JavaScript and CSS

I've designed a sleek top bar for my upcoming website project. Below is the CSS code snippet for creating this clean div bar: .topbar { display:block; width:100%; height:40px; background-color:#f5f5f5; } I'm looking to incorporate a simple .SWF ...

The child user interface component is failing to respond to keypress events within the parent component in an Angular project

I am facing a challenge in adding a keyboard shortcut to open a nested child UI Tab component through a keypress event. However, the Child nested tab can only be loaded after the Parent component is loaded first. Below is the structure of the UI tree: |-- ...

Unlocking the Power of Global Props in AlpineJS: A Step-by-Step Guide

I'm currently exploring AlpineJS after having some experience with React and basic knowledge of Vue. One thing that has puzzled me about AlpineJS is how to update a state value from within a function, similar to how it's done in React. Let' ...

Unexpected behavior in IE8 with setAttribute following Object extension

In my current project, I've implemented a custom micro-library similar to JQuery, but tailored specifically to my needs. window.$ = function(selector, context, undefined) { var getSelectorTest = function(selector, context, undefined) { ...

The closure in question received an undefined Angular parameter

Here is something similar to what I have: $scope.fetchData = function(path, save_to) { $http({method: 'GET', url: 'http://localhost:8001/www-root/' + path}). success(function(data, status, headers, config) { ...

Conditions for JQuery Ajax handlingIs there anything specific you would

I am looking to implement a try-catch scenario in Laravel where, if successful, a certain message will appear and if it fails, a different message will be displayed. However, when executed successfully, it seems to display the second message instead. $.a ...

Is it accurate that JavascriptResult displays javascript on the page in a string format?

I am new to .NET MVC and have been experimenting with different return types in MVC. However, I am having trouble getting the JavaScriptResult to work. In my controller, I have the following code: public ActionResult DoSomething() { string s = ...

Is FIREFOX better with plugins or extensions?

I have created a JavaScript function that changes the colors of images on web pages, specifically to assist colorblind individuals in identifying content. The entire development process was done using JavaScript within the Dreamweaver environment, along w ...

Ways to extend the timeout duration for Vercel Serverless functions

I've encountered an issue with my API endpoint on a NextJS project where it exceeds the 60-second time limit to execute. Despite being on a pro Vercel plan, I have been unable to extend the timeout limit successfully. Within the endpoint itself, I at ...

ng-grid Adjusts its Height Automatically

Is there a way to make ng-grid automatically resize its height based on the page size? The official documentation for ng-grid suggests using a fixed height, but I found a helpful solution in this link: .ngViewport.ng-scope { height: auto !important; ...

Can a single page be used to send email?

My PHP form is currently sending data to another page, and the layout does not look good. I want to keep the form on the same page so that when a user fills it out, the information is submitted without redirecting. If any of the inputs are empty, I would l ...

To enable the radio button upon clicking the list item in JavaScript, simply check the radio button

I am working with radio buttons Here is the HTML code: <input type="radio" class="first" name="bright" checked> <input type="radio" class="second" name="bright" > <input type=" ...

Executing a JavaScript function to trigger a PHP script that saves data into a MySQL database

I have a button in my HTML file that, when clicked, should insert data into a database and then reload the page. I am calling a JavaScript function within the onclick event to handle this. Below is the JavaScript function: function grandFinale() { i ...

Learn how to manipulate the DOM by dynamically creating elements and aligning them on the same line

Providing some context for my page: The section I have always contains a single input field. Below that, there is an "add" button which generates additional input fields. Since only one field is required on the screen, the following fields come with a "de ...

Enhancing the capabilities of my search and select filter beyond the boundaries of ng-app in AngularJS

In the controller, I have a directive that lists items using data from an API call. The HTML code for this is: <div ng-app="WWnetworkEvents"> <ul ng-controller ="networkEventsCtrl"> <networkevent-directive></networkevent-directiv ...

Ways to activate a different jQuery event by utilizing the output from a previously run jQuery event

I have a button on my website that looks like this: <a id="btn" class="button">Click Me!</a> When this button is clicked, it triggers a jQuery function as shown below: $("#btn").on("click", function() { $.ajax({ url: 'index.php&ap ...

Animate an svg icon to follow a designated path as the user scrolls

I am currently working on a project that involves animating a bee svg icon as the user scrolls through the website. The bee starts at the top and fills in a grey color line with pink as the user moves forward, and moves backward as the user scrolls back. Y ...

Is there a way to bypass the "Error: Another application is currently displaying over Chrome" message using Javascript or Typescript?

Can the "Another app is displaying over chrome error" be bypassed using JavaScript or TypeScript? Error Message: https://i.stack.imgur.com/iSEuk.png ...

Unexpected error from API call detected within Mint localhost Template Kits elements

Hello Everyone, hope you're all having a good day! Recently, I installed the Elementor and Envato Elements plugins on my localhost Linux Mint WordPress setup. After configuring permalinks and other settings in WordPress, I proceeded to browse Templat ...

Access the data from a JSON object within a v-select menu

<v-form :model='management'> <v-flex xs3 sm2 md3> <div class="form-group> <v-select :items="days" item-text='text' item-value='text' placeholder="MM" single-line attach v- ...