What is the best way to pass variables to a function in an Angular

How can I pass the variables year and monthGet to a function in an Angular service from a controller?

Service

myApp.factory('getJsonForCalendarService', function($resource, year, monthGet) {

        return $resource(
            '../rest/api.php',
            { method: 'getJsonForCalendar', year: year, monthGet:month},
            {'query': { method: 'GET', isArray: true }}
        );

});

Controller

$scope.getJsonData = getJsonForCalendarService.query(function (response, year, monthGet) {
});

Answer №1

The application's injector only instantiates your factory function once: To ensure this, make sure to follow these steps:

myApp.factory('getJsonForCalendarService',function($resource){
    return function(year,month){        
        return $resource(
            '../rest/api.php',
            { method: 'getJsonForCalendar', year: year, monthGet:month},
            {'query': { method: 'GET', isArray: true }}
        );    
    }
}

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

How can I implement a scroll functionality to navigate to the next item in a Vuetify v-carousel?

I'm currently working on a front page layout using the v-carousel component and I am looking to achieve automatic scrolling to the next item without the need for arrows or delimiters. How can I make this happen? Below is my current code: <template ...

I receive a notification when I interact with a form in React on the internet

Encountering an error when a user fills out the form I'm constructing: react_devtools_backend.js:4026 Warning: A component is changing an uncontrolled input to be controlled. This is likely caused by the value changing from undefined to a defined val ...

How can I convert HTML to PDF with CSS in AngularJS version 1?

Currently, I am working on a project that requires me to export HTML to PDF. It is crucial that the PDF retains the same design as seen in the browser, which means the CSS styles should be applied in the PDF file as well. I am utilizing AngularJS for the ...

The volume control does not work on Howler.js for iOS devices

In my Meteor React App, I have made some modifications to the React Howler plugin in order to play two audio tracks simultaneously. I have also added a crossfader feature to adjust the volume of both tracks at the same time. This functionality works perfec ...

Discover the basics of incorporating libraries using npm

As a beginner in JavaScript, I am looking to incorporate moment.js or another library into my project. However, I am unsure of how to properly set up my project so that I can import from the library. Here is how I have structured my HTML: <!DOCTYPE html ...

"Enhancing Real-Time Communication in Angular with Websockets and $rootScope's Apply

Currently, I am experimenting with an Angular application that utilizes a websocket to interact with the backend. I've encountered some challenges in getting Angular's data binding to function correctly. In this scenario, I have developed a serv ...

Can the name of the ngx-datatable-column be altered?

I recently started developing an angular2 web application that includes a ngx-datatable component. The header columns all have numeric names, but I would like to customize them in the view. Despite my efforts to research this issue, I haven't come ac ...

Transforming text elements into JSON format

My text contains a list of items formatted as follows: var text = "<li>M3-2200 (da2/M3-2200)</li><li>N3-2200 (da2/N3-2200)</li><li>Picasso (picasso/A500)</li><li>Picasso (picasso/A501)</li><li>Picasso ...

Send an array to a function with specified criteria

My current code successfully splits an array, but I need to pass a value when the array condition is met. For example, here is how the value is split into an array: var myArr = val.split(/(\s+)/); If the array in position 2 is empty, I need to use ...

Drag and Drop Feature using Angular with JQuery UI for Cloning Elements

I've been working on a web design project where I want to create a draggable user interface. https://i.sstatic.net/Be0Jk.png The goal is for users to click and drag different types of questions from the left side to the right side of the screen. Cu ...

Populate a bootstrap-select dropdown menu with an array of choices

After creating a table using datatables and adding an empty dropdown select on the footer with Bootstrap-select, here is the code snippet: <tfoot> <tr> <th><select class="selectpicker" multiple></select>< ...

New functionality introduced in JavaScript ES6: Sets

I am currently using a Set data structure to store unique primitive values, but I am facing an issue when trying to add unique objects based on their property values. Below is an example of my code: "use strict" var set = new Set(); var student1 = { ...

Retrieving the value of a JavaScript variable from an HTML document using Python

I am looking to extract the value of myJSONObject from an HTML document that includes javascript code with a JSON object. Here is an example snippet: <html> <head> </head> <body> <script type="text/javascript"> ...

Having trouble launching the Nuxt 3 development server because the module '@volar/typescript/lib/node/proxyCreateProgram' cannot be located

Whenever I attempt to execute npm run dev, the dev server initiates but encounters the following error: Cannot start nuxt: Cannot find module '@volar/typescript/lib/node/proxyCreateProgram Require stack: - node_modules\vite-plugin-checker&bsol ...

Converting a comma-separated string into individual values for ng-repeat

Here is my HTML code: <div class="jobDiv" data-dir-paginate="item in data.allJobs|filter:categoryFilterFn|orderBy:'item.PublishDate':true| itemsPerPage:10"> <h3> <a href="{{item.JobID}}">{{item.JobTitle}}</a> ...

Utilizing array iteration to display images

I am having trouble getting the images to display on my card component. The description appears fine, but the images are not rendering properly even though I have the image data in an array. Here is the Card Component code: export const Card = (props) =&g ...

Angular's implementation of a web socket connection

I am facing an issue with my Angular project where the web socket connection only opens upon page reload, and not when initially accessed. My goal is to have the socket start as soon as a user logs in, and close when they log out. Here is the custom socke ...

Oh no, the dreaded encounter with Gulp, Vue, Webpack, Babel causing an unexpected token import SyntaxError!

I have been struggling all day to make this work, but I haven't had any luck. If someone could provide some insight, it would be greatly appreciated. My goal is to set up an environment for working with ES6 files and Vue using Webpack. I have instal ...

How can I determine if a specific button has been clicked in a child window from a different domain?

Is there a method to detect when a specific button is clicked in a cross-domain child window that cannot be modified? Or determine if a POST request is sent to a particular URL from the child window? Below is an example of the HTML code for the button tha ...

Executing a JavaScript Function in the Background using Cordova

Despite the numerous questions and plugins available on this topic, finding a solution has proven to be elusive for me. The most highly recommended plugin for this issue can be found here. My goal is to run MyService in the background, subscribe to the ON ...