Closed zzczzc004 closed 7 years ago
I found I got an incorrect understanding about keywords this before, and solved the problem by change the way of register controller in the Routes.
Before:
router.post("/heroes", controller.create);
After:
router.post("/heroes", (req, res) => controller.create(req, res));
glad you got the resolution :)
I want to add a property in the Controller class. Like in the HeroController, I add a 'test' property, and I want to use it in the create function. But when create is invoke by the route, it show [TypeError: Cannot read property 'test' of undefined].
I think it's because typescript is simulate class but Javascript didn't have a class until ES6. I have use c# before and use Javascript and Typescript recently but not full understand it.