Lilith
Lilith

Reputation: 165

angularjs date issue : undefined

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

Upvotes: 0

Views: 205

Answers (1)

Hrishikesh Kale
Hrishikesh Kale

Reputation: 6548

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');

Upvotes: 1

Related Questions