当我收到 'catch' 回调时,'this' 是未定义的,即使使用箭头函数也是如此。有任何想法吗?
private all(req: Request, res: Response): void {
EntityRepository.getRepositoty(req.params.etName).then(repo => {
...
}).catch((err) => {
this.handleError(res, err); // here I get undefined.
});
}
Run Code Online (Sandbox Code Playgroud)
all func 是如何调用的。
它是基于 Express 路由调用的。
bind按照@jfriend00 的建议添加了mathod。
constructor() {
// Connect to database.
DataAccess.connect();
// Starts configuring routes for api
this.router = Router();
// Bad request due to absence of entity type.
this.router.get("/", (req, res) => {
res.statusCode = 400;
res.statusMessage = SysMsgs.error.noEntityTypeSpecified.message;
res.send();
});
// Added method 'bind'.
this.router.get(this.routeBase, this.all.bind(this)); …Run Code Online (Sandbox Code Playgroud) 当我的应用程序尝试与Web服务通信时,我收到错误
(407)需要代理身份验证(ISA Server需要授权才能完成请求.拒绝访问Web代理筛选器.)
我看了几个主题,但我无法理解.我正在使用VB.net