Angular $q .catch() method fails in IE8

前端 未结 3 842
旧时难觅i
旧时难觅i 2021-01-31 08:52

I\'m experiencing a weird bug on IE8 while trying to catch a promise reject (promise returned by a basic ngResource call) :

This code work with .then(

3条回答
  •  盖世英雄少女心
    2021-01-31 09:51

    You need to use bracket notation:

    promise.then(function(response) {
      // success
    })
    ["catch"](function(response) {
      // error
    });
    

    This is because IE8 implements ECMAScript 3 that does not allow bare keywords in dot notation. Modern browsers implement ECMAScript 5 that allows it.

    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.

提交回复
热议问题