我如何 运行 TypeScript 中的匿名函数?
How do I run an anonymous function in TypeScript?
我正在使用 Angular 2 的 http.post 发送一些数据并检索结果。得到结果后,我想 运行 一个函数,但匿名函数似乎不起作用。我该如何实现?
片段:
this.http.post("/login/login", this.model)
.subscribe(res => function () {
console.log('a', this.res);
},
error => function (e) {
console.log(e);
},
() => function () {
console.log("3");
} );
试试去掉函数这个词
this.http.post("/login/login", this.model)
.subscribe(res => () {
console.log('a', this.res);
});
匿名函数应该与打字稿一起使用。
您对箭头函数的语法是错误的想法。
尝试删除函数关键字 https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions
我正在使用 Angular 2 的 http.post 发送一些数据并检索结果。得到结果后,我想 运行 一个函数,但匿名函数似乎不起作用。我该如何实现?
片段:
this.http.post("/login/login", this.model)
.subscribe(res => function () {
console.log('a', this.res);
},
error => function (e) {
console.log(e);
},
() => function () {
console.log("3");
} );
试试去掉函数这个词
this.http.post("/login/login", this.model)
.subscribe(res => () {
console.log('a', this.res);
});
匿名函数应该与打字稿一起使用。 您对箭头函数的语法是错误的想法。 尝试删除函数关键字 https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions