The factory is not receiving any data from the controller

In a hypothetical scenario, picture a facility where inmates are housed in individual cells. My goal is to access a particular cell by invoking the API '/getparameters' which will provide me with the cell number. Subsequently, I intend to utilize this variable as the id for my factory implementation. Although no errors are being thrown, I'm not receiving any data either. What could be causing this issue?

var app = angular.module('myApp', ['ngResource']);

//app.factory('Params', function)
app.factory ('CellID', function($resource){
    return $resource('/my/api/cell/:id');
});

app.controller('CellCtrl', function($scope, $http, CellID){
    //employ $http to retrieve parameters, specifically, the cell number
    $http.get('/getparameters')
    .success(
        function(data) {
            var cellnumber = data.cellnum; 
            CellID.get({id:cellnumber}), function(data){
                $scope.info = data;
            }
        }
    ) 
});

Answer №1

You've incorrectly placed your parentheses in the code snippet:

CellID.get({id:cellnumber}), function(data){
    $scope.info = data;
}

Currently, this code is calling a get function with the cell number, not utilizing the result, and then adding a function without proper execution.

The correct approach should be:

CellID.get({id:cellnumber}/* <-- no parentheses here */, function(data){
    $scope.info = data;
}); // <-- use parentheses here (along with a semicolon)

Alternatively, you can simplify it like this:

$scope.info = CellID.get({id:cellnumber});

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

Applying CSS Filters can sometimes interfere with the functionality of 3D

While playing around with CSS transforms, I discovered that filters flatten the transforms just like setting transform-style: flat. var toggleFilter = function() { var div = document.getElementById("cube") if (div.className == "cube") { d ...

What is the best way to retrieve the ID of the input element using a jQuery object?

After submitting a form with checkboxes, I retrieve the jQuery object containing the checked input elements. var $form = $(e.currentTarget); var $inputs = $form.find("input.form-check-input:checked") Here is an example of how the inputs are stru ...

Alter the color of the initially chosen option in the dropdown selection

I'm struggling to modify the color of the initial selection while keeping the remaining selection-options at their default black color. Unfortunately, I haven't been successful in achieving this. Currently, all colors are #ccc. What I want is fo ...

Trouble with Angular Material

I have been experimenting with the demo for Angular Material toolbar. The default JavaScript code does not include any dependent modules, as shown below: angular.module('MyApp') .controller('AppCtrl', function($scope) { }); However, ...

What is the best way to pass a mask without using a plug-in when dealing with an input value in Vue.js?

As someone who has previously implemented the function using pure JavaScript, I am now faced with the challenge of incorporating it into vue.js and determining which lifecycle hooks are best suited for this task. This issue arises as I am a beginner prepar ...

Pass RGBA color code from JavaScript to Laravel controller

I have an exciting project where users need to select a color value in hex format. Once I retrieve this value in JavaScript, I convert it to Rgba format. Now, my challenge is figuring out how to send this converted value to the controller for database stor ...

What could be causing MS browsers to transform my object array into an array of arrays?

Noticing an interesting behavior with Microsoft browsers especially when dealing with data returned from our product API. It seems that the array of 52 product objects is being transformed into several arrays, each containing only 10 objects. Our error tr ...

Unable to add new Instance Properties in Vue.js within a Laravel project

I am attempting to develop a localization property similar to __('text') in Laravel blade template. I have set up a global window variable that contains all required data under the name window.i18n Below is my resourses/js/app.js file: require(& ...

Tips for calculating the total of an array's values

I am seeking a straightforward explanation on how to achieve the following task. I have an array of objects: const data = [ { "_id": "63613c9d1298c1c70e4be684", "NameFood": "Coca", "c ...

Trouble is arising in rendering events with years before 100 (specifically years 0000 - 0099) when using the ISO8601 format in fullCalendar

I've created a Calendar that showcases various events using fullcalendar. The events span from the years 0001 to 6000. Fullcalendar requires dates in ISO8601 format, and I am providing them as such. Events from the years 0100-6000 render perfectly w ...

Struggling to retrieve user input from a textfield using React framework

I'm having trouble retrieving input from a text-field in react and I can't figure out why. I've tried several solutions but none of them seem to be working. I even attempted to follow the instructions on https://reactjs.org/docs/refs-and-th ...

Rapidly update code changes using the development mode in Next.js with the VS Code Remote Container/devcontainer

Struggling to enable Next.js' Fast Refresh feature while using a VS Code Remote Container. Running npm run dev displays the app on localhost, indicating the container functions properly - but Fast Refresh remains ineffective. Next.js version: v11.0.1 ...

"Converting a database table record into a JavaScript array: Step-by-step guide

I'm currently expanding my knowledge of PHP by working on a small project. Within my database, I have a table called city_name which consists of columns for id, name, longitude, and latitude. Typically, this table contains around 10-15 rows. When a us ...

What is the best way to maintain the index of a for loop when incorporating AJAX to insert PHP data into an object?

Hey there, I'm diving into the world of AJAX and PHP implementation. I've hit a bit of a roadblock lately as I feel like I might be missing a simple solution. Currently, my code fetches data from a trove API using PHP, and for each item it appen ...

Show the value of the chosen checkbox using AngularJS

How can I display the selected checkbox value in a grid table on the same page when the save button is clicked? I have a form with textboxes, select boxes, and checkboxes that I am able to display in the table. However, I am struggling to figure out how to ...

Issue with loading the class directive using ng-class in certain scenarios

How can I load a 'class' directive using ng-class without creating an isolated scope? I want the directive to be loaded only when required based on ng-class conditions. Has anyone successfully implemented this approach? The directive is called u ...

How can Prisma be used to create a model for a database table with a hyphen in its name?

One of the tables in my database has a hyphen in its name, for example, "user-cars". Unfortunately, I am unable to change the name to "user_cars". Is there any way for me to name the model as "user_cars" while still making it reference the "user-cars" ta ...

How can I extract data from an XML file and include it in a JSON file using GulpJS?

Being relatively inexperienced with Gulp/Node programming, I am facing some difficulties while trying to accomplish a simple task :) Within my XML file, there exists a node like the following: <widget version="1.1"></widget> My goal is to ext ...

What causes the discrepancy in the output of `document.documentElement.childNodes` in JavaScript?

While working on my code exercise today, I came across a special case regarding the "document.documentElement.childNodes" property. Originally, I believed it to represent all child nodes within a tag as before. However, when implementing my code, I noticed ...

"Encountering issues with testing the controller of an Angular

I am facing difficulties while attempting to test a modal controller (developed using Angular UI Bootstrap). I simplified the test code as much as possible, but I keep encountering an error. Below is part of the modal controller: var controllersModule = ...