所以我想将一些string
值发送到我的节点服务器并在MySQL表中找到该值。
我有一个从服务
获取数据的组件ngOnInit() {
this.instructionsService.getAllInstructions().subscribe(instructions => {
this.instructions = instructions;
});
}
然后我有一个从node
服务器
getAllInstructions() {
return this.http.get('/api/profile/')
.map(res => res.json());
}
最后我有节点api
app.get('/profile',getAllInstructions);
function getAllInstructions(req,res){
connection.query("select * from users where id='somekindofid'",function(err, rows, fields) {
res.json(rows);
}
}
`
我想用我的组件发送的值' somekindofid' 替换
我该怎么做?
答案 0 :(得分:1)
您应该将/profile/:id
传递给其URL本身内的node方法。
同样,您应该将API路由更改为id
,其中app.get('/profile/:id',getAllInstructions);
function getAllInstructions(req,res){
connection.query("select * from users where id="+ req.params.id,function(err, rows, fields) {
res.json(rows);
}
}
是将从API的使用者传递的参数。
<强>节点强>
getAllInstructions(id) {
return this.http.get(`/api/profile/${id}`)
.map(res => res.json());
}
<强>服务强>
ngOnInit() {
let userId = 'pankaj';
this.instructionsService.getAllInstructions(userId).subscribe(instructions => {
this.instructions = instructions;
});
}
<强>组件强>
library(dplyr) # dplyr 0.5.0
library(lazyeval)
df <- data_frame(group = c(1, 2, 2, 3, 3, 3))
g <- "group"
df %>%
group_by_(g) %>%
summarise_(
n = n(),
sum = interp(~sum(col, na.rm = TRUE), col = as.name(g))
)
# Error in n() : This function should not be called directly