繁体   English   中英

我想在Angular的http get请求中将_id作为参数传递

[英]I want to pass the _id as parameter in http get request in Angular

  productSelect(_id){
    let headers = new Headers();
    headers.append('Content-Type', 'application/json');
    return this.http.get('http://localhost:3000/api/productSelect', { headers: headers, search: _id }).pipe(map(res => res.json()));
  }

index.js(节点)

router.get('/productSelect', (req, res, next) =>{
    let _id = req.query.search;
    console.log(_id);
    productSchema.aggregate([   
        { $lookup:
            {
                from: 'supplierschemas',
                localField: 'supplierId',
                foreignField: '_id',
                as: 'supplier'
            }
        },
        { $lookup:
            {
                from: 'brandschemas',
                localField: 'brandId',
                foreignField: '_id',
                as: 'brand'
            }
        },
        { $lookup:
            {
                from: 'categoryschemas',
                localField: 'categoryId',
                foreignField: '_id',
                as: 'category'
            }
        }

    ], (err, productSchema) =>{
        if(err) res.json(err);
        else res.json(productSchema);
    });
});

此代码返回“未知”。 如何解决这个问题? 以及如何添加传递参数进行汇总? 我想根据用户选择修改选择标签选项

看起来您需要req.query.search而不是req.body.search 从文档

req.query

查询路由中的字符串参数。 如果没有查询字符串,则为空对象{}。此属性是包含每个属性的对象

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM