0

Front-End

app.factory('CustomerService', function($http) {
    return {
        addCustomerToDb : function(customer) {
            return  $http.post('localhost:4000/new_info', customer)
                .success(function(response) {
                    //alert(JSON.stringify(data))
                    console.log(response.customer)
                });

            //   return $http({
            //     method:"POST",
            //     url: "localhost:4000/new_info",
            //     customer:customer
            // });
        }
    }   
});

app.controller("new_info", function($scope, CustomerService, $routeParams) {    
    $scope.register = function () {
        CustomerService.addCustomerToDb($scope.customer)
            .then(function(response) {
                console.log(response.$scope.customer);
            });
    };

});
Lex
  • 6,758
  • 2
  • 27
  • 42
  • I'm guessing it's the `console.log` in the controller that is not producing any output? The `response` object will likely not have a `$scope` property. What do you get if you change `console.log(response.$scope.customer);` to just `console.log(response);` or `console.log(response.customer);`? – Lex Aug 28 '18 at 22:52
  • Still not showing anything – Chirag Mittal Aug 28 '18 at 22:55
  • Is the `console.log` in your factory displaying anything? Also, I would recommend changing the `.success` to `.then` and you need to return the response object. I think you may be swallowing it which is why nothing is getting returned to the controller. – Lex Aug 28 '18 at 22:58
  • I tried .then but still its not showing anything – Chirag Mittal Aug 28 '18 at 23:01
  • Is `$scope.register` even called? Do you see the request in the browser network tab? – logee Aug 28 '18 at 23:58
  • $scope.register is called in an html file but doesn't show request in network tab . – Chirag Mittal Aug 29 '18 at 00:16
  • I think you are missing `return response.customer` after your `console.log` in factory. Also change `console.log(response.$scope.customer);` to `console.log(response)` – Ashish Aug 29 '18 at 07:16
  • https://github.com/ChiragMittal/posting - this is my github link . Plzz see and help me – Chirag Mittal Aug 29 '18 at 16:44

0 Answers0