0

Front End

customer.controller("single_customer", 
     function($scope, $http, $routeParams)
        {    
            $http.get('http://localhost:4000/customer/:id').then (function(data){
                // $scope.whichCustomer = $routeParams.id;
                $scope.customer = data;

                console.log($scope.customer)

            }).catch(function(err){
                    console.log(err);
            }); 


        }
);

Back-End

app.get("/customer/:id", (req, res) => {

    var user = String(req.params.id);
    console.log(user)

    Customers.find({id:user}, (err, items) => {
        if (err) res.status(500).send(err)

        res.status(200).send(items);
        console.log(items)
      });
    // console.log(Customers.find({id:user}));
    // res.send(Customers.find({id:user}));

   });

Mongoose schema

var Customers = mongoose.model('Customers',{
    id: {type:String , required:true} ,
    name: String ,
    city : String ,
    state : String ,
    gender : String ,
});
georgeawg
  • 48,608
  • 13
  • 72
  • 95
  • I would suggest to add a clearer title and also, it would help if you could better elaborate in words what the problem is. By doing so more people will be able to help you out. – Francesco Meli Aug 27 '18 at 23:16
  • Shouldn't you pass actual customer id in place of `:id` in your $http call? `$http.get('http://localhost:4000/customer/')` – Ashish Aug 28 '18 at 06:18

2 Answers2

0
customer.controller("single_customer", 
     function($scope, $http, $routeParams)
        {
            // $scope.whichCustomer = $routeParams.id;
            var base = "http://localhost:4000/customer/"
            var url = base + $routeParams.id;   
            $http.get(url).then (function(response){
                $scope.customer = response.data;  
                console.log($scope.customer)

            }).catch(function(err){
                    console.log(err);
            });    
        }
);
georgeawg
  • 48,608
  • 13
  • 72
  • 95
0

Try sending id as shown below:

customer.controller("single_customer", 
     function($scope, $http, $routeParams)
        {    
       $http.get("http://localhost:4000/customer/"+$routeParams.id}).then (function(data){
                // $scope.whichCustomer = $routeParams.id;
                $scope.customer = data;

                console.log($scope.customer)

            }).catch(function(err){
                    console.log(err);
            }); 

);
Saniya syed qureshi
  • 3,053
  • 3
  • 16
  • 22
  • I have a new issue .If you could help . https://stackoverflow.com/questions/52067133/no-console-log-answer-while-posting – Chirag Mittal Aug 28 '18 at 23:19