我想创建一个get方法,它有多个参数。在我的示例中,它只需要一个参数,但我需要再插入一个参数。在后端代码段中,你可以看到,我想要传递第二个参数,但我不知道该怎么做。我试着做辅助治疗,但不起作用。
我想要传递creater_group (它可以工作)和第二个参数作为created_by。
组件:
ngOnInit(): void {
const creater_group = localStorage.getItem('usergroup');
const created_by = localStorage.getItem('user')
this.getMessageNotifications(creater_group, created_by)
}
getMessageNotifications(creater_group) {
console.log(creater_group)
this.notificationService.getMessageNotifications(creater_group).subscribe(response => {
this.notifications = response.notification;
console.log(this.notifications);
})
}服务:
getMessageNotifications(creater_group){
return this.http.get(BASE_URL + 'messagenotifications/' + creater_group).pipe(
map(res => res.json()))
}后台: Nodejs。
function getMessageNotifications(req, res, next) {
var creater_group = String(req.params.creater_group);
db.any(
`SELECT
message_wall.message,
message_wall.created_at,
message_wall.id,
message_wall.seen,
message_wall.creater_group,
message_wall.created_by,
users.logout_date
FROM
message_wall,
users,
WHERE
message_wall.creater_group != $1
AND
user.username = $2
`, creater_group
)
.then(function (notification) {
res.status(200)
.json({
status: 'success',
notification: notification,
message: 'Retrieved notifications'
});
})
.catch(function (err) {
return next(err);
});
}发布于 2020-05-08 16:19:37
你可以试试这个
组件
ngOnInit(): void {
const creater_group = localStorage.getItem('usergroup');
const created_by = localStorage.getItem('user')
this.getMessageNotifications(creater_group, created_by)}
getMessageNotifications(creater_group,created_by) {
this.notificationService.getMessageNotifications(creater_group,created_by).subscribe(response => {
this.notifications = response.notification;
console.log(this.notifications);
})
}服务
getMessageNotifications(creater_group,created_by){
return this.http.get(BASE_URL + 'messagenotifications/' + creater_group +'/'+ created_by).pipe(
map(res => res.json()))}https://stackoverflow.com/questions/61674767
复制相似问题