2016-04-05 28 views
0

私はanglejsコントローラからnodejsへのデータとしてemailIdを送る必要があります。私はそれをgoogledしかし、私は解決策を得ていない、誰かが私を助けてください。

コントローラファイル:上記のコードで

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'); 
     }); 
} 

私はデータとしてemailを送ってきたが、Node.jsのファイルに私が要求してきておりません。

ノードのファイル:ここで

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); 
     } 
     }); 

    }; 
} 

私はconsole.log(req);を入れているが、本体部に私はbody{}、このように取得しています。

$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であなたがdataを利用することができますし、サーバーで使用すると、その値のを取得することができます:

+0

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

+0

apiを使ってapiを正しく動作させてみると、問題はありません。私の質問はどのようにGET方法。 –

+0

サーバーにデータを送信するときにPOSTを使用する必要があります。 – shammelburg

答えて

4

サンプルは、以下を参照してくださいGETを使用すると、paramsを利用することができますし、サーバーで、あなたはreq.queryにその値を得ることができます

$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

はい投稿が正しく機能しています。ありがとうございました。 –

0

はコンマ

と、URLの下に、このようにデータを送信する: req.body次のサンプルを参照してください0
url: 'http://localhost:7200/api/manage-product', 
method: 'GET', 
params: {emailData:yourEmaildata} 
関連する問題