I have a button, when I click on it, my code will send a HTTP request through all selected items with angular.forEach
in the first click I won't get any error or responses. from second click on the button and when my code try to send second part of $http requests I have an error.
error Error: undefined is not an object (evaluating 'apiFactory.likeRequest')
this is my controller:
app.controller('dashboardCtrl',
['$rootScope', '$scope', 'store', '$state','apiFactory','loginFactory','$http',
function($rootScope, $scope, store, $state, apiFactory, $http){
apiFactory.likeRequest(item["media_id"], data)
.then(function (response) {
console.log(response);
$scope.pressedIndexesObject.splice(index, 1);
}, function (error) {
console.log(JSON.stringify(error));
$scope.pressedIndexesObject.splice(index, 1);
});
});
and this ones is my request factory:
angular.module('instagrow')
.factory('apiFactory', ['$http', function ($http) {
var dataFactory = {};
dataFactory.likeRequest = function (media_id,data) {
return $http.post('https://api.instagram.com/v1/media/'+ media_id + '/likes', data, config);
};
return dataFactory;
}]);
I tried to do it without factory or with closure as an argument but exception remained.
UPDATE: another type of request that tried was single instance from $http for each item like this :
angular.forEach($scope.pressedIndexesObject, function(item) {
var media = item
console.log('im indexed' +JSON.stringify( $scope.pressedIndexesObject));
$http.post('https://api.instagram.com/v1/media/'+ media["media_id"] + '/likes', data)
.then(function (response) {
console.log(response);
$scope.pressedIndexesObject.splice(index, 1);
}, function (error) {
console.log(JSON.stringify(error));
$scope.pressedIndexesObject.splice(index, 1);
});
});