Questions tagged [global-variables]

Global variables, also known as universal variables, are variables that can be accessed and utilized by all elements within a software component.

Creating a universal variable in Laravel with just one word

There's something I'm not sure about, I'd like to create a variable called @ads in the view files so that whenever @ads is used, it would call a specific div element: <div class="ads"> @if(condition) some block of codes... ...

In order to either pass a component variable as a parameter or set it as a global variable

Currently, I am in the process of restructuring my Angular2/Ionic2 code and seeking advice on the best practice for my specific situation. Within my component, I have declared a variable (this.questions) that I need to utilize in my service method. There ...

I'm struggling to understand the issue with my global variables in my Python project

I’m stuck on my python school assignment and can’t seem to find the error I’m making. It’s either a global name not defined issue or syntax errors when I try different things. Hoping someone can help me out. Check out the assignment details below: ...

Developing a universally accessible variable for utilization in various functions

I'm having trouble understanding why 'currentPos.LatLng' is undefined when trying to access it outside the function even though it's part of an object. I want to be able to retrieve the current position values to use them in another function. Can someone ...

issue with global variable not functioning properly within a sub-function in Angular 7

I have a question that needs clarification import { Component, OnInit,ViewChild,ElementRef } from '@angular/core'; import {Http,Headers} from "@angular/http"; import { Observable, Subject, asapScheduler, pipe, of, from, interval, merge, ...

What is the most efficient approach to save a value for future utilization in a subsequent function? I've heard that exploiting global variables is highly unfavorable

So I have this code that can be found at http://jsfiddle.net/8j947/10/. It returns either true or false for the variable isLive. My main concern now is how to utilize the variable onLive in a subsequent function. While I've encountered some solutions on ...

Sharing API Results with All Components in Angular 7 using BehaviorSubject

My goal is to optimize an API call that fetches data about the current user (such as their username, full name, group memberships, email address, and more) by ensuring it's only made once per user session and that the data is shared across all compone ...

Utilizing Enum Types in Angular Templates

I have a set of server-side enums that I need to send to an Angular application. My goal is to access these enums in the following manner: <select ng-options="type.name as type.value for type in Enums.TYPES" /> I've attempted various methods ...

Utilizing a global variable for tracking iterations in a nested for loop in Python

I am facing an issue while using a global variable x as a counter in my for loops. I have two lists, col_values_X_right and col_values_Y_right, which store coordinates. I intend to create 15 different plots using these coordinates, as the '-' separators wi ...

Sending data from a controller to an AngularJS app config

I'm fairly new to working with Angular. Within my Angular application, I have implemented token authentication. To handle situations where my backend returns a 401 error, I am using an HTTP interceptor that triggers a login process using a refresh tok ...

Changing the global type in TypeScript

Currently, I am incorporating two third-party TypeScript libraries into my project. Interestingly, both of these libraries expose a global variable with the same name through the Window interface. However, they offer different methods for interacting with ...

How to access a static TypeScript variable in Node.js across different files

I encountered a situation like this while working on a node.js project: code-example.ts export class CodeExample { private static example: string = 'hello'; public static initialize() { CodeExample.example = 'modified'; } ...

What is the necessity of explicitly requesting certain core modules in Node.js?

The documentation explains that certain core modules are included in the Node.js platform itself and are specified within the source code. The terminology can get a bit confusing when it comes to details. The term "global objects" (or standard built-in obj ...

Understanding PHP functions and variable scope within the Smarty template engine

Currently, I am working with Smarty version 2.6.27 and facing an issue where PHP functions are unable to access global variables: {php} $a = "should be global"; function test(){ global $a; echo $a; } test(); {/php} Despite trying to make the variable $a ...

The process of accessing a global JavaScript variable within an AngularJS directive is a common task

I spent some time searching for an article that addresses my specific question but came up empty-handed. My dilemma revolves around accessing a pre-defined JavaScript global variable within an AngularJS built-in directive. Let's say I declare the followi ...

transfer data from local array to global variable

Need help with returning array values using console.log(array);, currently it's displaying empty value []. Any tips or suggestions would be greatly appreciated. var array = []; var maxLength = 3; var delay = 250; //Shortened the delay var ticker = {}; ...

Using Vue global variables within the <head> section of HTML documents

On my website, I am utilizing Vue version 2.6.11. In the src/main.js file, I have set some global variables based on guidance from this thread as shown below: /* global variables */ Vue.prototype.$frontUrl = "http://localhost:8080/"; Vue.prototyp ...

Employing global variables in Express.js is a common practice that can provide

I have a situation where I need to access variables from one router in another router. Would using a middleware be the most efficient way to achieve this, and if so, how would I implement it? Alternatively, if I simply declare global variables at the sta ...

Employing global variables in JavaScript files with Vue3

In my Vue3 project, I have defined global variables like this: app.config.globalproperties.$locale = locale A composable function has been created to dynamically retrieve these global variables: import { getCurrentInstance ) from 'vue' export function us ...

How to use TypeScript variables in React applications

In my current project, I am attempting to customize a Fabric JS component (Dropdown) using styled-components within a React component. The specific CSS class names are defined in a file located at office-ui-fabric-react/lib/components/Dropdown/Dropdown.sc ...

Leveraging the capabilities of Express functions on the client side through the require method in Node.js

Trying to access the configuration variables set in the file named test.js which contains -- var aws = require('aws-sdk'); exports.connect = function(){ return aws; } Now, I am attempting to access it upon an OnClick event taking place in the bro ...

Guide to Making a Next Button in Tkinter for Easy Frame Switching

In my tkinter quiz program, each question has its own frame. After the user selects the correct answer from a radiobutton list, a window pops up allowing them to navigate between questions. Here's an example: https://i.stack.imgur.com/Hij8g.png Instead of ...

Why are imported modules unable to reach global variables in Node?

As I delve deeper into using ES6 and organizing my code across multiple files for better readability and version control, I've encountered an issue that has me puzzled. In one of my scenarios, I have a class defined in a separate file called class.js, ...

Find the value of a JavaScript string variable using an alternative name

My latest JavaScript function is designed to fetch JSON data from either a server or local files on any browser. This piece of code processes JSON from two sources: an XMLHttpRequest response, or a variable imported via script. In the case of the latter, ...

Global jQuery variables are unexpectedly coming back as "undefined" despite being declared globally

I need to save a value from a JSON object in a global variable for future use in my code. Despite trying to declare the country variable as global, it seems like it doesn't actually work. $.getJSON(reverseGeoRequestURL, function(reverseGeoResult){ ...

Javascript error: attempting to access property value of a null object

Is there a way to access the value of 'nilai' ID in a different function? var sis = 'SELECT nis, nama_siswa FROM nilai_tugas'; connection.query(sis, function(err, rows, cols) { if(err){ console.log ...