角$ Q .catch()方法在IE8失败 [英] Angular $q .catch() method fails in IE8
问题描述
我遇到IE8的一个奇怪的错误,而试图抓住一个承诺拒绝(承诺通过一个基本的 ngResource
调用返回):
I'm experiencing a weird bug on IE8 while trying to catch a promise reject (promise returned by a basic ngResource
call) :
与。然后这code的工作(成功,失败)
语法:
promise.then(function(response) {
// success
},
function(response) {
// error
});
但这个失败,。然后(成功).catch(失败)
语法:
promise.then(function(response) {
// success
})
.catch(function(response) {
// error
});
和IE的错误指向 .catch()
行是:
and the IE error pointing to the .catch()
line is :
预计标识符
我是不是做错了什么?有人重现呢?或者是一种常见的IE8由于受限的关键字?
Am I doing something wrong ? someone reproduce it ? or is it a common IE8 due to restricted keyword ?
感谢
推荐答案
您需要使用括号标记:
promise.then(function(response) {
// success
})
["catch"](function(response) {
// error
});
这是因为IE8实现的ECMAScript 3,不允许用点表示光秃秃的关键字。现代浏览器实现的ECMAScript 5,允许它。
This is because IE8 implements ECMAScript 3 that does not allow bare keywords in dot notation. Modern browsers implement ECMAScript 5 that allows it.
很多图书馆别名 .catch
与另一个关键字。然而,角的承诺是建立它的方式不是简单的延长 $ Q
的承诺。因此, [抓]
将不得不这样做。请注意,这也是最后
。
A lot of libraries alias .catch
with another keyword. However, the way Angular promises are built it is not simple to extend $q
promises. So ["catch"]
would have to do. Note this is also true for finally
.
这篇关于角$ Q .catch()方法在IE8失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!