javascript - AngularJS - cordova android 上的意外 token "catch"

标签 javascript android angularjs cordova try-catch

我构建了一个简单的网络应用程序在 cordova wbeview 中运行,当我将它安装在 android 4.1 上时它运行没有问题但是当我将它安装在 Android 2.3.6 上时(很老是的)

Unexpected token "catch" file.js LINE 134

这意味着这个 catch 表达式不能工作:

 $http({
            'method':'GET',
            'url': appWS + '/api/find'
          }).then(function (response) {

           //
          }).catch(function (err) {

           //
          });

我不明白为什么不支持 catch 可能是太旧的 android 好吧,但我该如何解决这个问题?

谢谢,感谢您的帮助

最佳答案

尽管@Pointy 的观点,.catch() 是使用 angualr promises(以及一般的 q 库)做事的常用方法。我想这实际上是您正在测试的 android 版本中的一个错误(事实证明它可以在较新的版本中运行)。

您可以尝试使用(等效的)方括号表示法来调用该函数,如下所示:

$http(options)
  .then( function () { /* do stuff */ } )
  ['catch']( function () { /* handle errors */ } );

或内部函数sintax

$http(options)
      .then( function () { /* do stuff */ }, function () { /* handle errors */ } );

这可能会解决问题。

关于javascript - AngularJS - cordova android 上的意外 token "catch",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27043403/

相关文章:

javascript - 不合逻辑的 Passport 验证方法参数

javascript - 为什么这些嵌套的 forEach 循环会这样?

javascript - 在wordpress中禁用移动 View 的js

android - 如何在 Firebase 中存储 BigDecimal?

android - 水平回收 View 中的 9 补丁背景

javascript - 从父级 JavaScript 访问跨域 IFrame DOM 属性

android - GitKit Android 快速入门失败 "Sign in with Google",错误代码为 : 9

javascript - 在javascript中合并数组内的数组

angularjs - 无法在 AngularStrap 上重现日期选择器示例

javascript - 键盘显示时 Ionic ion-content 不向下滚动 (Android)