2016-05-27 31 views
1

为什么在setTimeout()(模拟帖子和回复)中设置$scope.blured不起作用?使用setTimeout更改范围属性

Plunker

$scope.bluryLines = function(value) { 
    $scope.blured = true; 

    if (value === '' || value === undefined) { 
     console.log('value is empty'); 
    } else { 
     console.log(value); 
    } 

    //faking a post 
    setTimeout(function() { 
     $scope.blured = false; 
     console.log('log'); 
    }, 1000); 
}; 

按下按钮cleares它的时候了。

$scope.removeOverlay = function() { 
    $scope.blured = false; 
}; 
+0

它会记录日志吗? – JohnPan

回答

2

setTimeout不运行摘要。改为使用角度$timeout服务。

app.controller('MainCtrl', function($scope, $timeout) { 

    $scope.bluryLines = function(value) { 
     $scope.blured = true; 

     //faking a post 
     $timeout(function() { 
      $scope.blured = false; 
     }, 1000); 
    }; 

}); 
+0

@ Dejan.S(当然)... =) – evolutionxbox