2014-03-24 147 views
0

我想將一個變量從控制器傳遞到Angularjs應用程序(前端)和nodejs後端中的DAO服務。Angularjs將變量從控制器傳遞到dao服務

這裏是我的控制器:

$scope.afficherProfils = function() { 
    $http.get(configuration.URL_REQUEST + '/profile') 
     .success(function(data) { 
      $scope.owner = data._id; 
      console.log('$scope.owner =========>'); 
      console.log($scope.owner); 
      $http.get(configuration.URL_REQUEST + '/listerProfil', { 
       owner: $scope.owner 
      }) 
       .success(function(data) { 
        console.log('$scope.listeProfils =========>'); 
        console.log(data); 
        $scope.listeProfils = data; 
       }); 
     }); 
}; 

我打電話/ profile中獲得已添加的配置文件的帳戶的_id,在那之後我打電話內成功/ listerProfil並通過業主參數。

,在我的DAO服務的代碼如下:

exports.all = function(req, res) { 
    console.log('req.body ================================>'); 
    console.log(req.body); 
    Profil.find({ 
    owner: req.body.owner 
    }, function(err, profils) { 
    if (err) { 
     res.send({ 
     'result': 'error' 
     }); 
    } else { 
     res.send(profils); 
    } 
    }); 
}; 

,我不知道爲什麼我的req.body是空的,當我做的console.log

什麼想法?

+1

使用$ http.post發送正文中的數據。 –

回答

1

HTTP的CRUD(Create- $ http.post,讀 - $ http.get,更新 - $ http.put,Dlete- $ http.delet)

$http.get-It used to get the value means this body contain empty value 

$http.post-It used to create value means this body contain data (your are post some data to server) 

$http.update-It used to update exit value this body also contain data 

$http.delete-It used to delete exit value this body contain empty(send through param(?id=1111)) 

因此改變你的代碼http.get到http.post

相關問題