angular ui router - How can I access $stateParams from a service in AngularJS? -
this service:
metronicapp.factory('itemservice', ['$http', '$sessionstorage', '$stateparams', function($http, $sessionstorage, $stateparams) { return { save: function(data, success, error) { return $http.post(baseurl + '/shops/' + $sessionstorage.currentshop.id + '/menus/' + $stateparams.menuid + '/categories/' + $stateparams.categoryid + '/items', data).success(success).error(error); }, update: function(data, success, error) { return $http.put(baseurl + '/items/' + data.id, data).success(success).error(error); }, savetranslation: function(data, success, error) { return $http.post(baseurl + '/itemtranslation', data).success(success).error(error); }, get: function(itemid, success, error) { return $http.get(baseurl + '/items/' + itemid).success(success).error(error); }, getall: function(categoryid, success, error) { console.log("menu id is: " + $stateparams.menuid); return $http.get(baseurl + '/shops/' + $sessionstorage.currentshop.id + '/menus/' + $stateparams.menuid + '/categories/' + $stateparams.categoryid + '/items').success(success).error(error); } }; }]);
i want able use $stateparams.menuid in getall method. @ time, url is:
/menus/54/categories/56/items
but $stateparams null. how can them?
one way solve problem pass in stateparams controller @ time executing service functions. make parameter on functions need data, , provide when executing functions.
metronicapp.factory('itemservice', ['$http', '$sessionstorage', function($http, $sessionstorage) { return { save: function(data, stateparams, success, error) { return $http.post(baseurl + '/shops/' + $sessionstorage.currentshop.id + '/menus/' + stateparams.menuid + '/categories/' + stateparams.categoryid + '/items', data).success(success).error(error); }, update: function(data, stateparams, success, error) { return $http.put(baseurl + '/items/' + data.id, data).success(success).error(error); }, savetranslation: function(data, stateparams, success, error) { return $http.post(baseurl + '/itemtranslation', data).success(success).error(error); }, get: function(itemid, stateparams, success, error) { return $http.get(baseurl + '/items/' + itemid).success(success).error(error); }, getall: function(categoryid, stateparams, success, error) { console.log("menu id is: " + stateparams.menuid); return $http.get(baseurl + '/shops/' + $sessionstorage.currentshop.id + '/menus/' + stateparams.menuid + '/categories/' + stateparams.categoryid + '/items').success(success).error(error); } }; }]);
Comments
Post a Comment