【问题标题】:@Get decorator not working correctly in node.js@Get 装饰器在 node.js 中无法正常工作
【发布时间】:2019-05-17 18:52:54
【问题描述】:

我在我的 Restful Node 应用程序中使用 @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 })

    if (item) {
        res.send({
            success: true,
            data: item
        })
    } else {
        this.errorHandler(res, 'No Data with provided id')
    }
}

我在基本控制器中定义了getOneById 函数,路径是来自Params 装饰器的id。 但是当我尝试通过console.log(id); 登录时,id 是错误的 有人可以帮忙吗?

【问题讨论】:

    标签: javascript node.js typescript decorator


    【解决方案1】:

    你应该在装饰函数中添加async

    【讨论】:

    • 对我来说很好。
    猜你喜欢
    • 1970-01-01
    • 2021-01-06
    • 2015-11-09
    • 2021-06-30
    • 2012-01-20
    • 2020-07-25
    • 1970-01-01
    • 1970-01-01
    • 2017-04-30
    相关资源
    最近更新 更多