0

Imagine a prison with prisoners in separate cells, and I want to be able to be able to access a specific cell by calling the API '/getparameters' that will return the cell number, and then pass that variable in as the id for my factory. This is what I have come up with. No error are returned, but no data is being returned either. Where am I going wrong?

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){
    //use $http to getparameters, specifically, the cell number
    $http.get('/getparameters')
    .success(
        function(data) {
            var cellnumber = data.cellnum; 
            CellID.get({id:cellnumber}), function(data){
                $scope.info = data;
            }
        }
    ) 
});
2
  • 1
    Check the network tab, what are the status' of the requests? Commented Dec 29, 2014 at 18:36
  • Each status reads '200 OK' Commented Dec 29, 2014 at 18:40

1 Answer 1

1

You've got your parentheses in the wrong places:

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

This is doing a get with the cellnumber, doing nothing with the result, and then just dropping a function into the ether.

I think you meant to do this:

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

You should also be able to just do this:

$scope.info = CellID.get({id:cellnumber});
Sign up to request clarification or add additional context in comments.

1 Comment

BINGO! DING DING DING DING! Winner winner chicken dinner! Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.