在AngularJS版本升级后,无法读取未定义错误的属性“$$状态”

时间:2017-07-06 11:15:53

标签: javascript angularjs bower

我一直在与 AngularJS 合作,将我们项目的版本从1.2.16升级到1.6.4。由于我们使用bower作为包管理器,我已经更新了bower.json的必要部分,如下所示:

{
"name": "takademi",
"version": "0.0.0",
"dependencies": {
  "angular": "1.6.4",
  "json3": "~3.3.1",
  "es5-shim": "~3.1.0",
  "angular-cookies": "1.6.4",
  "angular-sanitize": "1.6.4",
  "angular-animate": "1.6.4",
  "angular-route": "1.6.4",
  "angular-bindonce": "~0.3.1",
  "restangular": "~1.4.0",
  "angular-base64": "~2.0.2",
  "lodash": "~2.4.1"
},
"devDependencies": {
"angular-mocks": "1.2.16",
"angular-scenario": "1.2.16"
},
"appPath": "app"
}

在此次更新后,我运行了该项目。现在我可以看到angular的版本为1.6.4,但我得到了以下错误:

*** process.env.ENV is not defined, assuming 'prod' env
t @ bundle.js:4776
angular.js:14525 TypeError: Cannot read property '$$state' of undefined
    at then (angular.js:16799)
    at addPromiseLikeThing (angular-busy.js:67)
    at angular-busy.js:22
    at Object.forEach (angular.js:403)
    at Object.tracker.reset (angular-busy.js:18)
    at angular-busy.js:175
    at $watchCollectionAction (angular.js:17859)
    at Scope.$digest (angular.js:17999)
    at Scope.$apply (angular.js:18269)
    at done (angular.js:12387)
(anonymous) @ angular.js:14525
getMarketPlace Failed to load resource: the server responded with a status of 401 (Unauthorized)
angular.js:14525 Possibly unhandled rejection: {"data":{"status":401,"module":0,"code":1000,"message":"AUTHENTICATION_REQUIRED","develo    perMessage":null,"moreInfo":null},"status":401,"config": {"method":"GET","transformRequest":[null],"transformResponse":[null],"jsonpCallbackParam":"callback","params":{"v":967},"headers":{"Accept":"application/json, text/plain, */*"},"url":"/portal/rest/market-place/getMarketPlace"},"statusText":"Unauthorized"}
(anonymous) @ angular.js:14525
(anonymous) @ angular.js:11008
processChecks @ angular.js:16860
$digest @ angular.js:17971
$apply @ angular.js:18269
done @ angular.js:12387
completeRequest @ angular.js:12613
requestLoaded @ angular.js:12541

据我所知,它只是说明我新升级的AngularJS 1.6.4文件不支持$$state关键字用法。这个错误来自Angular自己的文件,而不是显示我们开发的文件。

以下是chrome浏览器导航我显示错误的函数 - 第16799行angular.js:

  function Promise() {
this.$$state = { status: 0 };
  }

  extend(Promise.prototype, {
    then: function(onFulfilled, onRejected, progressBack) {
      if (isUndefined(onFulfilled) && isUndefined(onRejected) && isUndefined(progressBack)) {
        return this;
      }
      var result = new Promise();

      this.$$state.pending = this.$$state.pending || [];
      this.$$state.pending.push([result, onFulfilled, onRejected, progressBack]);
      if (this.$$state.status > 0) scheduleProcessQueue(this.$$state);

      return result;
    },

    'catch': function(callback) {
      return this.then(null, callback);
    },

    'finally': function(callback, progressBack) {
      return this.then(function(value) {
        return handleCallback(value, resolve, callback);
      }, function(error) {
        return handleCallback(error, reject, callback);
      }, progressBack);
    }
  });

我已经在SO和谷歌搜索了一下,但我找不到任何相关的帖子或解释我的问题。大多数答案都与Ruby有关,或者做出反应:

angular showing TypeError: Cannot read property 'state' of undefined

Uncaught TypeError: Cannot read property 'state' of undefined

react: uncaught TypeError: Cannot read property 'state' of undefined

由于我不了解AngularJS和凉亭的整体特征,我不清楚这些答案。

你能帮我个忙吗?

提前致谢!

1 个答案:

答案 0 :(得分:1)

AngularJS小组不会创建angular-busy module。函数addPromiseLikeThing看起来很可疑,是进入$ q库之前执行的最后一件事。使用'promiseLike'对象伪造$ q库可能是导致错误的原因。

此外,AngularJS V1.6改变了拒绝处理的方式。错误消息:

  

angular.js:14525可能未处理的拒绝:{“data”:{“status”:401,

是这些变化的结果。

有关详细信息,请参阅AngularJS Developer Guide - Migrating to V1.6 ($q)