0

I have a problem with my application at a date.

I have an API made in symfony, and a client under ionic in Angularjs. I test with Postman, everything works fine, but when I try to set up the feature I have an error.

My date is "undefined"

when I try to communicate the application with my API.

Here is my code:

My service:

var userDispo = function(id,date){
    var id = window.localStorage.getItem('antenne');
    return $http({
           method  : 'GET',
           url     : API_ENDPOINT.url + '/user/dispo/' + id + '/' + date,
           headers : {Authorization : 'Bearer ' + $http.defaults.headers.common.Authorization}
       }).then(function(result) {
       return result.data;
    });
};

my controller :

.controller('UserDispoCtrl',
function ($scope, $stateParams, $ionicLoading, AppService) {
$ionicLoading.show();
$scope.date = new Date().toISOString().slice(0, 10);
console.log($scope.date);
AppService.userDispo($scope.date).then(function (response){
    console.log(response);        
});

})

in my controller, the first "console.log($scope.date)" shows me well "2018-04-25"

and right after I have the following error:

GET https://xxxxxxx/app_dev.php/api/user/dispo/antenne/19/undefined 404 (Not Found)

I do not understand where the error comes from, my URL should be like the following:

https://xxxxxxx/app_dev.php/api/user/dispo/19/2018-04-25

Someone would have a track or solution suggested please?

thank you in advance

4
  • In your service function you have (id,date) and when you call it you only pass the first parameter so AppService.userDispo($scope.date), so you are passing the id not the date. Commented Apr 25, 2018 at 7:45
  • my id is already present in the url, it's the '19', the only thing that does not show is my date Commented Apr 25, 2018 at 7:54
  • check arguments order Commented Apr 25, 2018 at 7:58
  • Oh yes it's true !! my bad :/ thanks a lot Commented Apr 25, 2018 at 8:00

1 Answer 1

1

yes it will be undefined as while calling your function userDispo it takes 2 parameter id and date, the first parameter is id and second is the date.

for while calling userDispo you need to pass

AppService.userDispo($scope.id,$scope.date)

and define id globally to access

 $scope.id = window.localStorage.getItem('antenne');
Sign up to request clarification or add additional context in comments.

Comments

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.