2016-04-05 26 views
0

Angularjs denetleyicisinden veriye emailId göndermem gerekir. Ben googled ama çözüm almadım, birisi bana yardım edin.

kontrolör dosyası: Ben veri olarak email gönderilen ancak node.js dosyasında ben istekte almıyorum Yukarıdaki kodda

function ManageProductController($http, $scope, $mdDialog, $document, $location, $localStorage) 
{ 
    var vm = this; 
    vm.email = $localStorage.email; 

    $http({ 
      url: 'http://localhost:7200/api/manage-product', 
      method: 'GET', 
      data: {email:vm.email} 
     }).success(function(res) { 
      //$scope.productlist = res; 
      //console.log(res.result); 
      vm.result=res.result; 

      //vm.docs=res.docs; 
     }, function(error) { 
      console.log(error); 
      alert('here'); 
     }); 
} 

.

düğüm dosyası:

İşte
router.get('/manage-product', function(req, res){ 
    //console.log('I received get request'); 

    console.log(req); 
    var findProducts = function(db, callback) { 
     var cursor =db.collection('proInfo').find().toArray(function(err, docs){ 
      if(err){ 
      callback(new Error("Some problem")); 
      }else{ 
      callback(null,docs); 
     } 
     }); 

    }; 
} 

Ben console.log(req); koyduk ama vücut bölümünde sadece böyle body{} alıyorum.

$http({ 
      url: 'http://localhost:7200/api/manage-product', 
      method: 'GET', 
      params: {email:vm.email} //at server it will be req.query.email 
     }).success(function(res) { 

      //access returned res here 

     }, function(error) { 
      //handle error here 
     }); 

POST ile data yararlanabilir ve sunucuda bu değer de alabilirsiniz:

+0

api'yi http: // localhost: 7200/manage-product ' – zzlalani

+0

api kullanarak düzgün şekilde çalıştırmayı deneyin, bu bir sorun değildir ve sorum şu: GET kullanarak açısal düğümden verileri nasıl gönderiyorum yöntem. –

+0

Bir sunucuya veri gönderirken POST kullanmalı. – shammelburg

cevap

4

numunede aşağıdaki bkz GET ile params yararlanabilir ve sunucuda sen req.query söz konusu değeri alabilirsiniz

$http({ 
      url: 'http://localhost:7200/api/manage-product', 
      method: 'GET', 
      data: {email:vm.email} //at server it will be req.body.email 
     }).success(function(res) { 

      //access returned res here 

     }, function(error) { 
      //handle error here 
     }); 
+0

Evet gönderi düzgün çalışıyor. Teşekkür ederim. –

0

virgülle

ile url altında böyle veri göndermek: req.body aşağıdaki örneğe bakın 0
url: 'http://localhost:7200/api/manage-product', 
method: 'GET', 
params: {emailData:yourEmaildata} 
İlgili konular