It looks like $rootScope.appUrl
is undefined
when you call $http.post()
. Try logging the value of $rootScope.appUrl
to the console to make sure. If it's undefined
, set it to whatever you need to match the URL that your backend expects.
Edit: I'm not familiar with the specifics of Angular or what exactly gets passed to this method, but you can be a little more robust by checking to see if the variable is defined, like this:
$scope.saveProduct = function() {
var url = 'products.json';
if($rootScope && $rootScope.appUrl) {
url = $rootScope.appUrl + '/' + url;
}
console.log('call saveProduct');
$http
.post(url, $scope.book)
.success(function(data, status, headers, config) {
$location.path('/product');
})
.error(function(data, status, headers, config) {});
}