【问题标题】:Angularjs passing variables from controller to dao serviceAngularjs将变量从控制器传递到dao服务
【发布时间】:2014-05-01 17:40:49
【问题描述】:

我正在尝试将变量从控制器传递到 Angularjs 应用程序(前端)和 nodejs 后端中的 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);
    }
  });
};

我不知道为什么当我执行 console.log 时我的 req.body 是空的

有什么想法吗?

【问题讨论】:

  • 使用 $http.post 发送正文中的数据。

标签: node.js angularjs mongodb mongoose


【解决方案1】:

HTTP-CRUD(创建-$http.post,读取-$http.get,更新-$http.put,删除-$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

【讨论】:

    猜你喜欢
    • 2014-05-09
    • 2013-06-15
    • 2014-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-02
    • 2016-09-30
    • 1970-01-01
    相关资源
    最近更新 更多