【发布时间】:2019-11-11 13:41:25
【问题描述】:
我正在尝试将 8 位字符串数组作为 angular 的输入,并将其作为参数传递给 node.js 端点,如下所示,如果我只有一个字符串,下面的效果很好,如下面的硬编码所示req.query.params 的数组字符串在 node.js api 中效果很好,但是如何将 8 位字符串数组作为输入并传递给 node.js?
在html中:
<textarea rows="6" [(ngModel)]="enteredValue"></textarea>
<hr>
<button (click)="get_radar_lifecycle_data()">Search</button>
在component.ts中
get_radar_lifecycle_data(){
const params = new HttpParams().set('params', this.enteredValue);
this.http.get('http://localhost:3000/api/radar_life_cycle3',{params})
.subscribe(response => {
console.log(response);
this.newPost = response
});
}
node.js
数组的硬编码字符串到req.query.params效果很好
app.get("/api/radar_life_cycle3", (req, res, next) => {
console.log(req.query.params)
Radar_life_cycle.find({orgRadar: {$in:["51509646","51643617"]}})
.then(documents => {
res.status(200).json({
message: "Posts fetched successfully!",
posts: documents
});
});
});
实际的api调用
app.get("/api/radar_life_cycle3", (req, res, next) => {
console.log(req.query.params)
Radar_life_cycle.find({orgRadar: {$in:req.query.params}})
.then(documents => {
res.status(200).json({
message: "Posts fetched successfully!",
posts: documents
});
});
});
【问题讨论】:
-
尝试使用
put调用get。 -
为什么用 put 而不是 get?这将如何解决这个问题?
标签: javascript node.js angular mean-stack