Is there a way to transfer variable or data between two function expressions?

One of my function expressions looks like this:

$scope.myCourse = function(param1, param2) {
  $scope.courseName = param2;
  $scope.courseType = param1
} 

I am trying to access the variable/data from $scope.myCourse in another function expression as shown below:

$scope.updateCourse = function() {
  // How can I access/use $scope.courseName and $scope.courseType from $scope.myCourse here?
}

However, I keep getting 'undefined' when attempting to do so:

$scope.updateCourse = function() {
      console.log($scope.courseName, 'and', $scope.courseType, 'are in current selection. Are you fine to change the COURSE and TYPE?')
    }

Answer №1

To make $scope.courseName and $scope.courseType easily accessible from any function, it's best to declare them outside of the function.

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

The revalidateTag and revalidatePath features in Next.js are currently not functioning as expected

I attempted to utilize the revalidateTag and revalidatePath functions with Next.js version 14.2.3. The objective was: there is a server action to fetch a list of items. also, there is a server action to add an item. upon successful addition of an item, I ...

Filtering JSON data becomes seamless with the use of AngularJS

Is there a way to pass JSON data obtained from services.js to filter.js for filtering purposes? For instance: JSON data: {"name" :"stackoverflow"} Services.js: Created a service to retrieve JSON data {"getjsondataservice" } Controller: Acce ...

Dynamic Search Feature Using AJAX on Key Press

Currently, I have developed an AJAX search function that retrieves keyword values upon key up and triggers the script. The objective is to update the content area with results in alphabetical order as the user types each key. However, the issue I am facin ...

Using Javascript and jQuery to convert text into a tag

I'm attempting to use JavaScript to send a message on twitch.tv by modifying the textarea in the chatbox. <textarea class="tw-textarea tw-textarea--no-resize " placeholder="Send message" data-a-target="chat-input" data-test-selector="chat-input" s ...

"Error in Visual Studio: Identical global identifier found in Typescript code

I'm in the process of setting up a visual studio solution using angular 2. Initially, I'm creating the basic program outlined in this tutorial: https://angular.io/docs/ts/latest/guide/setup.html These are the three TS files that have been genera ...

`json_encode does not output a UTF-8 character`

I send an AJAX request to the PHP server, and receive back an array encoded in JSON. This array has only two indexes. When I log it using console.log(), this is what I see: {"1":"\u00d9\u0081\u00db\u008c\u00d9\u0084\u0 ...

I am facing an issue with Angular 14 and Webpack 5, where certain unnecessary nodejs modules seem to be hindering me from successfully serving

I have recently started working on a cutting-edge Angular 14 application. My current node version is v14.20.0, and npm version is 8.17.0. Despite my best efforts, I seem to be facing an issue with multiple nodejs dependencies being included in my project ...

Tips on allowing the backend file (app.js) to handle any URL sent from the frontend

In my Express app, I have two files located in the root directory: index.js and index.html. Additionally, there is a folder named "server" which contains a file named app.js that listens on port 3000. When running index.html using Live Server on port 5500 ...

Leverage Reveal.js within Next.js by installing it as an npm package

I am currently working on a project that requires integrating Reveal.js with Next.js. However, I am having trouble displaying the slides properly. Every time I try to display them, nothing shows up. Even after attempting to display some slides, I still en ...

Adding a specific element to an array using JQuery

I am in the process of developing a web application using jQuery to track goals and habits. Users can set a main goal such as 'Discipline' and then add sub-goals or habits related to that main goal (e.g. 'exercise every day'). Organizi ...

When using Material UI Autocomplete, the selected option should automatically be populated in the input field

When a user navigates through the choices using the arrow keys on their keyboard, I extract the value from the highlighted option to update the current input value (which has its own state). However, when the title or value of the option is saved as the i ...

Refresh your jQuery function without the need to reload the entire page

Is there a way to update a function's parameters without reloading the entire page? For instance, if I modify the 'style' dropdown value as shown in the URL image, can it be passed to the accordion function so that the accordion's color ...

The function Promise.all typically yields an array with nested arrays

Inside my node Router, the following code snippet is implemented: router.get("/single-base/:id", (req, res) => { Base.find({ _id: req.params.id }) .then(bases => { let basefetches = []; for (let base of bases) { ...

Mastering Angular Service Calls in TypeScript: A Comprehensive Guide

In the midst of my TypeScript angular project, I am aiming to revamp it by incorporating services. However, I have encountered an issue where when calling a function within the service, the runtime does not recognize it as the service class but rather the ...

Adding new elements without repeating them

Having an issue with appending an element to the end of a span on my webpage. The problem arises when there are multiple spans, causing the element to duplicate itself across all spans instead of going only at the very end of the last span. Any suggestions ...

Easily changing the state of a specific array item using React

I'm having trouble updating the state of a specific item in an array called reviews. Can someone guide me on how to achieve this? The following code snippet is not working as expected: this.setState({ reviews[2].current: true }); Below is the comp ...

Encountering Typescript errors when trying to destructure a forEach loop from the output of

There are different types categorized based on mimetypes that I am currently working with. export type MimeType = 'image' | 'application' | 'text'; export type ApplicationMimeType = '.pdf' | '.zip'; expor ...

Laravel's Vue component is experiencing issues with loading Axios response data

Hey everyone, I hope you're all doing well! I'm facing a bit of an issue with passing data from an axios response to the data property. The data is successfully fetched from the database and displayed in the console, but when I try to display it ...

Ways to transmit data from autocorrect to a higher-level class

Previously, I raised a question about passing state for React via props on Stack Overflow: Laggy TextField Updates in React. I have now revamped my code using ChrisG's approach, where I store states in the parent component FormSection and pass them a ...

Choose or deselect images from a selection

I am currently working on a feature for an album creation tool where users can select photos from a pool of images and assign them to a specific folder. However, I'm facing difficulty in selecting individual photos and applying customized attributes t ...