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条经验 获得超13个赞
$timeout(function(){ //any code in here will automatically have an apply run afterwards});
_.defer(function(){$scope.$apply();});
- 3 回答
- 0 关注
- 1467 浏览
添加回答
举报