3 回答

TA貢獻1813條經驗 獲得超2個贊
不要使用這種模式
-這將導致的錯誤多于解決的錯誤。即使你認為它能解決一些問題,它卻沒有。
$digest
$scope.$$phase
.
if(!$scope.$$phase) { //$digest or $apply}
$scope.$$phase
"$digest"
"$apply"
$digest
$apply
$digest
$apply
$digest
$apply
$digest
別這樣
if (!$scope.$$phase) $scope.$apply()
,這意味著
$scope.$apply()
在呼叫堆棧中不夠高。

TA貢獻1836條經驗 獲得超13個贊
$$phase
$timeout(function() { // anything you want can go here and will safely be run on the next digest.})
window.gapi.client.load('oauth2', 'v2', function() { var request = window.gapi.client.oauth2.userinfo.get(); request.execute(function(response) { // This happens outside of angular land, so wrap it in a timeout // with an implied apply and blammo, we're in action. $timeout(function() { if(typeof(response['error']) !== 'undefined'){ // If the google api sent us an error, reject the promise. deferred.reject(response); }else{ // Resolve the promise with the whole response if ok. deferred.resolve(response); } }); });});

TA貢獻2065條經驗 獲得超14個贊
$timeout(function(){ //any code in here will automatically have an apply run afterwards});
_.defer(function(){$scope.$apply();});
- 3 回答
- 0 關注
- 1533 瀏覽
添加回答
舉報