Closed ErikMartensson closed 5 years ago
As it turns out, I didn't read the documentation carefully enough. A colleague of mine figured out that the example I was following is currently only supported in TypeScript and that Babel for now doesn't support decorators in function parameters (no, not even with the transform-function-parameter-decorators
plugin).
So this is what solved it, binding the Param decorator to my method with the Bind decorator.
import { Controller, Bind, Get, Param } from '@nestjs/common'
@Controller('cats')
export class CatController {
@Get(':id')
@Bind(Param())
findOne(params) {
console.log(params) // <- Logs my parameters now
return 'This action returns all cats'
}
}
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
I'm submitting a...
Current behavior
The param decorator, in my controller, is always returning
undefined
. I get the same result even if I try to pick out a specific parameter, like in the tutorial. The route itself works fine. I can add a POST route too with no problem.Expected behavior
I was hoping for an object, where the only property inside would be the id parameter from the route. Alternatively, picking out a specific route parameter would extract that one only, but it doesn't work either. Like so:
Minimal reproduction of the problem with instructions
I've been following the tutorial here down to the section about "Route parameters".
Environment