在 $digest 阶段复制它时,Angular 似乎被 Chrome(可能还有其他浏览器)XMLHttpRequest 的“打开”状态绊倒了。当访问 XMLHttpRequest.status 字段时,它会引发异常。我的实际用例没有绑定到状态字段;XMLHttpRequest 对象只是我 $watch 的数组中另一个对象的一个成员。
所以,
a) Angular 是否应该更聪明地处理这种情况并忽略异常?
b)有没有办法让Angular在消化包含对象时忽略字段或对象?
c) 其他解决方法建议?
这是一个例子。这个 HTML+Javascript ( JSFiddle ):
<div ng-app ng-controller="TestCtrl">
<h2>XMLHttpRequest.status: {{ xhr.status }}</h2>
</div>
function TestCtrl($scope) {
$scope.xhr = new XMLHttpRequest();
$scope.xhr.open('POST', 'http://localhost:8000/api/medias', true);
}
导致此错误:
Error: INVALID_STATE_ERR: DOM Exception 11
Error: An attempt was made to use an object that is not, or is no longer, usable.
at eval (eval at Jb (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.0.3/angular.min.js:74:389), <anonymous>:16:4)
at d.fn.x.assign (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.0.3/angular.min.js:63:120)
at Object.j (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.0.3/angular.min.js:52:126)
at Object.e.$digest (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.0.3/angular.min.js:84:286)
at Object.e.$apply (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.0.3/angular.min.js:86:469)
at http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.0.3/angular.min.js:15:396
at Object.d [as invoke] (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.0.3/angular.min.js:26:401)
at pb (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.0.3/angular.min.js:15:317)
at jc (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.0.3/angular.min.js:15:178)
at http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.0.3/angular.min.js:159:424 angular.min.js:60