Javascript @使decorator在node.js中无法正常工作
我在Restful节点应用程序中使用@DecoratorsJavascript @使decorator在node.js中无法正常工作,javascript,node.js,typescript,decorator,Javascript,Node.js,Typescript,Decorator,我在Restful节点应用程序中使用@Decorators @Get('/:id') getUser(@Response() res: any, @Params('id') id: string) { this.getOneById(res, id) } // In Base Controller async getOneById(@Response() res: any, id: number) { const item = await this.getOne({ id })
@Get('/:id')
getUser(@Response() res: any, @Params('id') id: string) {
this.getOneById(res, id)
}
// In Base Controller
async getOneById(@Response() res: any, id: number) {
const item = await this.getOne({ id })
if (item) {
res.send({
success: true,
data: item
})
} else {
this.errorHandler(res, 'No Data with provided id')
}
}
我已经在基本控制器中定义了getOneById
函数,并从Params decorator中定义了它的id
路径。
但是当我试图通过console.log(id)登录时,id
是错误的代码>
有人可以帮忙吗?你应该在装饰功能中添加async
,对我来说很好用。