使用setTimeout更改scope属性

时间:2016-05-27 14:17:08

标签: javascript angularjs

为什么在$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);
};

按下按钮立即清除它。

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

1 个答案:

答案 0 :(得分:2)

<div class ='article'> <span class='author'> John doe</span> <h3>title</h3> (...) <div class='comments'> <div class='row'> <span class='author'>Whining anon</span> <div class='content'> (...) </div> </div> </div> </div> 没有运行摘要。请改用角度$timeout服务。

setTimeout