how to pass the dynamic variable to setInterval method

前端 未结 2 1373
礼貌的吻别
礼貌的吻别 2021-01-27 07:54

i want to refresh/reload the method in every 30 seconds. but im not able to send the variable data to another function i.e setInterval.how to pass variable in the setInterval me

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-27 08:07

    you can do it in various way,

    example:

    //set data
    window.deviceId=Id
    

    and use it in settimout

    setInterval(function () {
                $scope.getPIRData(window.deviceId);//unable to pass id here
            }, 30000)
    

    but you can declare any global variable of the settimeout outer scope, then that variable will be available into the settimeout call back function, because then it will be treated as Closures

提交回复
热议问题