3 回答

TA貢獻(xiàn)1813條經(jīng)驗(yàn) 獲得超2個(gè)贊
不要使用這種模式
-這將導(dǎo)致的錯(cuò)誤多于解決的錯(cuò)誤。即使你認(rèn)為它能解決一些問(wèn)題,它卻沒(méi)有。
$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貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超13個(gè)贊
$$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貢獻(xiàn)2065條經(jīng)驗(yàn) 獲得超14個(gè)贊
$timeout(function(){ //any code in here will automatically have an apply run afterwards});
_.defer(function(){$scope.$apply();});
- 3 回答
- 0 關(guān)注
- 1530 瀏覽
添加回答
舉報(bào)