As I delve into learning Angular, my approach involves shifting all the business logic to services.
However, I encountered an error while attempting a post request within a service:
Cannot read property 'post' of undefined
Provided below is a snippet of code:
UrlApp.controller('UrlFormCtrl', UrlFormCtrl);
UrlApp.factory('addUrlService', addUrlService);
function UrlFormCtrl($scope, $http) {
console.log('Initializing Url Form Controller');
$scope.addUrl = addUrlService.bind(null, $http);
}
function addUrlService($scope, $http){
console.log('Initializing addUrlService');
return $http.post('urls/create', {'test':'test'}).then(function(response){
return response.data;
});
}
I'm in the early stages of understanding Angular, so pinpointing the exact issue is challenging for me. Can you spot any potential problems?