Ng-Show无法正常运行

时间:2018-07-20 11:10:23

标签: html css angularjs mean-stack

$scope.stay = function() {
    alert("Inside Keep me In")
    $scope.timed = false;
    $scope.isLogStatus = true;
}

$scope.displayAlert = function() {
    $scope.timed = true;
    alert("inside display")
}

function idleTimer() {
    var t;
    $window.onmousemove = resetTimer; // catches mouse movements
    $window.onmousedown = resetTimer; // catches mouse movements
    $window.onclick = resetTimer; // catches mouse clicks
    $window.onscroll = resetTimer;
    //window.reload=$scope.stay();   // catches scrolling
    // window.onkeypress = resetTimer;  //catches keyboard actions

    function logout() {
        //Adapt to actual logout script
        $scope.displayAlert();
        alert('insinde logout');
        //  delete $window.localStorage.user;
        //  location.href="/";
    }

    function reload() {
        $window.location = self.location.href; //Reloads the current page
    }

    function resetTimer() {
        alert("timer reset")
        clearTimeout(t);
        // t = setTimeout(logout, 600000);  // time is in milliseconds (1000 is 1 second)
        $timeout(function() {
            alert("timout triggered");
            $scope.displayAlert();
        }, 9000); // time is in milliseconds (1000 is 1 second)
    }
}
idleTimer();

我使用的是html以上格式,如果我保留,则默认使用

$scope.timed=true;

正在工作 当我单击“登录”时,我正在做

 $scope.timed=false;

如果时间超过10分钟,我又要

$scope.timed=true;

(不会触发ng-show) 然后显示不起作用

这是控制者正在发生的事情

$scope.stay = function() {
    alert("Inside Keep me In")
    $scope.timed = false;
    $scope.isLogStatus = true;
}

$scope.displayAlert = function() {
    $scope.timed = true;
    alert("inside display")

}

function idleTimer() {
    var t;

    window.onmousemove = resetTimer; // catches mouse movements
    window.onmousedown = resetTimer; // catches mouse movements
    window.onclick = resetTimer; // catches mouse clicks
    window.onscroll = resetTimer;
    //window.reload=$scope.stay();   // catches scrolling
    // window.onkeypress = resetTimer;  //catches keyboard actions

    function logout() {
        //Adapt to actual logout script
        $scope.displayAlert();
        alert('insinde logout');
        //  delete $window.localStorage.user;
        //  location.href="/";
    }

    function reload() {
        window.location = self.location.href; //Reloads the current page
    }

    function resetTimer() {
        // alert("timer reset")
        clearTimeout(t);
        // t = setTimeout(logout, 600000);  // time is in milliseconds (1000 is 1 second)
        t = setTimeout(logout, 9000); // time is in milliseconds (1000 is 1 second)
    }
}
idleTimer();
// Get the topbar menu
$scope.menu = Menus.getMenu('topbar');

1 个答案:

答案 0 :(得分:0)

问题出在您调用logout函数的方式上。您是通过角度框架外部进行调用的,这意味着角度将不会运行消化循环,因此范围中的任何更改都不会反映到视图< / strong>。

要进行验证,您可以使用$timeout将代码包装在注销功能中。请不要忘记将其添加到dependencies中。

$timeout(function(){
   $scope.displayAlert();
});

理想情况下,您应该使用angular wrappers,例如$window的{​​{1}}和window的{​​{1}}。通过自动执行此操作,可以监视更改并相应地运行摘要循环。