javascript - SyntaxError: Unexpected token u at Object.parse (native) in Ionic -
recipeservice.js
recipedetails: function(recipe_id) { $http({ method: 'post', header: { 'content-type': 'application/x-www-form-urlencoded' }, url: 'http://localhost/admin-recipick/home/ajaxselectrecipes', data: recipe_id }).then( function success(response) { returnrecipedata = response.data; console.log(response.data); }, function error(response) { returnrecipedata = response.data; console.log(response.data); // handle error } ); }
controllers.js
$scope.recipedetails = function(recipe_id) { var getdatarecipe = getrecipeservice.recipedetails(recipe_id); if (getdatarecipe != "null") { recipeservice.setobject('recipick', getdatarecipe); var s = recipeservice.getobject('recipick'); console.log(s) $state.go('app.porkmenudo'); } else { $ionicpopup.alert({ title: 'login failed!', template: 'please check credentials!' }); } }
as can see in recipeservice returning right object want if go controller , object giving me error. , have factory getting object
.factory('recipeservice', function($window) { return { set: function(key, value) { $window.localstorage[key] = value; }, get: function(key, defaultvalue) { return $window.localstorage[key] || defaultvalue; }, setobject: function(key, value) { $window.localstorage[key] = json.stringify(value); }, getobject: function(key) { return json.parse($window.localstorage[key] || '{}'); }, clearstorage: function(key) { $window.localstorage.removeitem(key); } } });
what should do?
your recipedetails
needs return promise
. service method not returning data.
Comments
Post a Comment