how to pass the dynamic variable to setInterval methodhow to refresh method in every 30 seconds using setinterval in angular jsWhy are AngularJS $http success/error methods deprecated? Removed from v1.6?Stop setInterval call in JavaScriptHow do JavaScript closures work?How can I merge properties of two JavaScript objects dynamically?How do I check if an element is hidden in jQuery?How do I remove a property from a JavaScript object?How do I redirect to another webpage?How do I include a JavaScript file in another JavaScript file?How to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?How do I return the response from an asynchronous call?

Why would a propellor have blades of different lengths?

Why did the "Orks" never develop better firearms than Firelances and Handcannons?

CPA filed late returns, stating I would get money; IRS says they were filed too late

Do the 26 richest billionaires own as much wealth as the poorest 3.8 billion people?

What is this arch-and-tower near a road?

Do intermediate subdomains need to exist?

What can a novel do that film and TV cannot?

Sleepy tired vs physically tired

List of Implementations for common OR problems

Bypass with wrong cvv of debit card and getting OTP

Could you sell yourself into slavery in the USA?

What are the differences of checking a self-signed certificate vs ignore it?

What is the addition in the re-released version of Avengers: Endgame?

Should you add specific garden-fresh herbs to a stew at the beginning or the end?

Phrasing "it says" or "it reads"

What is meant by perfect, imperfect consonance and dissonance?

What is exact meaning of “ich wäre gern”?

What is the difference between a historical drama and a period drama?

Milky way is orbiting around?

how to convert Timestring to seconds

Are there advantages in writing by hand over typing out a story?

Does Evolution Sage proliferate Blast Zone when played?

Why did C++11 make std::string::data() add a null terminating character?

My players like to search everything. What do they find?



how to pass the dynamic variable to setInterval method


how to refresh method in every 30 seconds using setinterval in angular jsWhy are AngularJS $http success/error methods deprecated? Removed from v1.6?Stop setInterval call in JavaScriptHow do JavaScript closures work?How can I merge properties of two JavaScript objects dynamically?How do I check if an element is hidden in jQuery?How do I remove a property from a JavaScript object?How do I redirect to another webpage?How do I include a JavaScript file in another JavaScript file?How to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?How do I return the response from an asynchronous call?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-1















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 method.while adding static variable its working but how can i pass the id to setInterval method



 var app = angular.module('PIR_Detection', []);
app.controller('myCtrl', function ($scope, $http, $window)
$scope.sel_val = 0;
$scope.DefaultLabel = "Loading.....";
var post = $http(
method: "get",
url: "../data.json",
dataType: 'json',
data: ,
headers: "Content-Type": "application/json"
);
post.success(function (data, status)
$scope.Customers = data;
);
post.error(function (data, status)
);

$scope.getPIRData = function (id)
var url = "/PIRDetails/GetPIRStatus/" + id;


$http.get(url)
.then(function (response)
$scope.myWelcome = response.data;
$scope.pirstatus = base64toHEX($scope.myWelcome.dataFrame);
$scope.timestamp = getIST (response.data.timestamp);
$scope.rssi = response.data.rssi;
deviceid = id;

);
;
setInterval(function ()
$scope.getPIRData("100010102");//unable to pass id here
, 30000)

);









share|improve this question






















  • So how were you doing it with a varaible?

    – epascarello
    Mar 25 at 18:36






  • 1





    In general you should use $interval when using AngularJS. setInterval will work, but if you get in the habit of using it you'll eventually wonder why your view is not updating in certain circumstances.

    – Lex
    Mar 25 at 20:08











  • Also the $http Service is not a drop-in replacement for jQuery ajax. The dataType property is ignored, the application/json header is unnecessary, and the .success and .error methods are deprecated and removed from AngularJS V1.6.

    – georgeawg
    Mar 25 at 20:39


















-1















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 method.while adding static variable its working but how can i pass the id to setInterval method



 var app = angular.module('PIR_Detection', []);
app.controller('myCtrl', function ($scope, $http, $window)
$scope.sel_val = 0;
$scope.DefaultLabel = "Loading.....";
var post = $http(
method: "get",
url: "../data.json",
dataType: 'json',
data: ,
headers: "Content-Type": "application/json"
);
post.success(function (data, status)
$scope.Customers = data;
);
post.error(function (data, status)
);

$scope.getPIRData = function (id)
var url = "/PIRDetails/GetPIRStatus/" + id;


$http.get(url)
.then(function (response)
$scope.myWelcome = response.data;
$scope.pirstatus = base64toHEX($scope.myWelcome.dataFrame);
$scope.timestamp = getIST (response.data.timestamp);
$scope.rssi = response.data.rssi;
deviceid = id;

);
;
setInterval(function ()
$scope.getPIRData("100010102");//unable to pass id here
, 30000)

);









share|improve this question






















  • So how were you doing it with a varaible?

    – epascarello
    Mar 25 at 18:36






  • 1





    In general you should use $interval when using AngularJS. setInterval will work, but if you get in the habit of using it you'll eventually wonder why your view is not updating in certain circumstances.

    – Lex
    Mar 25 at 20:08











  • Also the $http Service is not a drop-in replacement for jQuery ajax. The dataType property is ignored, the application/json header is unnecessary, and the .success and .error methods are deprecated and removed from AngularJS V1.6.

    – georgeawg
    Mar 25 at 20:39














-1












-1








-1








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 method.while adding static variable its working but how can i pass the id to setInterval method



 var app = angular.module('PIR_Detection', []);
app.controller('myCtrl', function ($scope, $http, $window)
$scope.sel_val = 0;
$scope.DefaultLabel = "Loading.....";
var post = $http(
method: "get",
url: "../data.json",
dataType: 'json',
data: ,
headers: "Content-Type": "application/json"
);
post.success(function (data, status)
$scope.Customers = data;
);
post.error(function (data, status)
);

$scope.getPIRData = function (id)
var url = "/PIRDetails/GetPIRStatus/" + id;


$http.get(url)
.then(function (response)
$scope.myWelcome = response.data;
$scope.pirstatus = base64toHEX($scope.myWelcome.dataFrame);
$scope.timestamp = getIST (response.data.timestamp);
$scope.rssi = response.data.rssi;
deviceid = id;

);
;
setInterval(function ()
$scope.getPIRData("100010102");//unable to pass id here
, 30000)

);









share|improve this question














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 method.while adding static variable its working but how can i pass the id to setInterval method



 var app = angular.module('PIR_Detection', []);
app.controller('myCtrl', function ($scope, $http, $window)
$scope.sel_val = 0;
$scope.DefaultLabel = "Loading.....";
var post = $http(
method: "get",
url: "../data.json",
dataType: 'json',
data: ,
headers: "Content-Type": "application/json"
);
post.success(function (data, status)
$scope.Customers = data;
);
post.error(function (data, status)
);

$scope.getPIRData = function (id)
var url = "/PIRDetails/GetPIRStatus/" + id;


$http.get(url)
.then(function (response)
$scope.myWelcome = response.data;
$scope.pirstatus = base64toHEX($scope.myWelcome.dataFrame);
$scope.timestamp = getIST (response.data.timestamp);
$scope.rssi = response.data.rssi;
deviceid = id;

);
;
setInterval(function ()
$scope.getPIRData("100010102");//unable to pass id here
, 30000)

);






javascript angularjs






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 25 at 18:28









krishna mohankrishna mohan

678 bronze badges




678 bronze badges












  • So how were you doing it with a varaible?

    – epascarello
    Mar 25 at 18:36






  • 1





    In general you should use $interval when using AngularJS. setInterval will work, but if you get in the habit of using it you'll eventually wonder why your view is not updating in certain circumstances.

    – Lex
    Mar 25 at 20:08











  • Also the $http Service is not a drop-in replacement for jQuery ajax. The dataType property is ignored, the application/json header is unnecessary, and the .success and .error methods are deprecated and removed from AngularJS V1.6.

    – georgeawg
    Mar 25 at 20:39


















  • So how were you doing it with a varaible?

    – epascarello
    Mar 25 at 18:36






  • 1





    In general you should use $interval when using AngularJS. setInterval will work, but if you get in the habit of using it you'll eventually wonder why your view is not updating in certain circumstances.

    – Lex
    Mar 25 at 20:08











  • Also the $http Service is not a drop-in replacement for jQuery ajax. The dataType property is ignored, the application/json header is unnecessary, and the .success and .error methods are deprecated and removed from AngularJS V1.6.

    – georgeawg
    Mar 25 at 20:39

















So how were you doing it with a varaible?

– epascarello
Mar 25 at 18:36





So how were you doing it with a varaible?

– epascarello
Mar 25 at 18:36




1




1





In general you should use $interval when using AngularJS. setInterval will work, but if you get in the habit of using it you'll eventually wonder why your view is not updating in certain circumstances.

– Lex
Mar 25 at 20:08





In general you should use $interval when using AngularJS. setInterval will work, but if you get in the habit of using it you'll eventually wonder why your view is not updating in certain circumstances.

– Lex
Mar 25 at 20:08













Also the $http Service is not a drop-in replacement for jQuery ajax. The dataType property is ignored, the application/json header is unnecessary, and the .success and .error methods are deprecated and removed from AngularJS V1.6.

– georgeawg
Mar 25 at 20:39






Also the $http Service is not a drop-in replacement for jQuery ajax. The dataType property is ignored, the application/json header is unnecessary, and the .success and .error methods are deprecated and removed from AngularJS V1.6.

– georgeawg
Mar 25 at 20:39













2 Answers
2






active

oldest

votes


















0














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






share|improve this answer























  • i did like this document.getElementById("deviceid").innerHTML = id; $scope.getPIRData(document.getElementById("deviceid").innerHTML); can we do it like this?

    – krishna mohan
    Mar 25 at 18:46












  • thanks its working for me window.deviceid

    – krishna mohan
    Mar 25 at 18:50


















0














Courtesy of @tvanfosson:



You probably want to have a function that creates the interval timer for you. Pass in the parameter to the function so its value is captured in the function closure and retained for when the timer expires.



function createInterval(f,dynamicParameter,interval) setInterval(function() f(dynamicParameter); , interval); 


Then call it as createInterval(funca,dynamicValue,500); Obviously you can extend this for more than one parameter. And, please, use more descriptive variable names. :)






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55344331%2fhow-to-pass-the-dynamic-variable-to-setinterval-method%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    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






    share|improve this answer























    • i did like this document.getElementById("deviceid").innerHTML = id; $scope.getPIRData(document.getElementById("deviceid").innerHTML); can we do it like this?

      – krishna mohan
      Mar 25 at 18:46












    • thanks its working for me window.deviceid

      – krishna mohan
      Mar 25 at 18:50















    0














    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






    share|improve this answer























    • i did like this document.getElementById("deviceid").innerHTML = id; $scope.getPIRData(document.getElementById("deviceid").innerHTML); can we do it like this?

      – krishna mohan
      Mar 25 at 18:46












    • thanks its working for me window.deviceid

      – krishna mohan
      Mar 25 at 18:50













    0












    0








    0







    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






    share|improve this answer













    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







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 25 at 18:39









    Md. Mahamudul HasanMd. Mahamudul Hasan

    5705 silver badges15 bronze badges




    5705 silver badges15 bronze badges












    • i did like this document.getElementById("deviceid").innerHTML = id; $scope.getPIRData(document.getElementById("deviceid").innerHTML); can we do it like this?

      – krishna mohan
      Mar 25 at 18:46












    • thanks its working for me window.deviceid

      – krishna mohan
      Mar 25 at 18:50

















    • i did like this document.getElementById("deviceid").innerHTML = id; $scope.getPIRData(document.getElementById("deviceid").innerHTML); can we do it like this?

      – krishna mohan
      Mar 25 at 18:46












    • thanks its working for me window.deviceid

      – krishna mohan
      Mar 25 at 18:50
















    i did like this document.getElementById("deviceid").innerHTML = id; $scope.getPIRData(document.getElementById("deviceid").innerHTML); can we do it like this?

    – krishna mohan
    Mar 25 at 18:46






    i did like this document.getElementById("deviceid").innerHTML = id; $scope.getPIRData(document.getElementById("deviceid").innerHTML); can we do it like this?

    – krishna mohan
    Mar 25 at 18:46














    thanks its working for me window.deviceid

    – krishna mohan
    Mar 25 at 18:50





    thanks its working for me window.deviceid

    – krishna mohan
    Mar 25 at 18:50













    0














    Courtesy of @tvanfosson:



    You probably want to have a function that creates the interval timer for you. Pass in the parameter to the function so its value is captured in the function closure and retained for when the timer expires.



    function createInterval(f,dynamicParameter,interval) setInterval(function() f(dynamicParameter); , interval); 


    Then call it as createInterval(funca,dynamicValue,500); Obviously you can extend this for more than one parameter. And, please, use more descriptive variable names. :)






    share|improve this answer



























      0














      Courtesy of @tvanfosson:



      You probably want to have a function that creates the interval timer for you. Pass in the parameter to the function so its value is captured in the function closure and retained for when the timer expires.



      function createInterval(f,dynamicParameter,interval) setInterval(function() f(dynamicParameter); , interval); 


      Then call it as createInterval(funca,dynamicValue,500); Obviously you can extend this for more than one parameter. And, please, use more descriptive variable names. :)






      share|improve this answer

























        0












        0








        0







        Courtesy of @tvanfosson:



        You probably want to have a function that creates the interval timer for you. Pass in the parameter to the function so its value is captured in the function closure and retained for when the timer expires.



        function createInterval(f,dynamicParameter,interval) setInterval(function() f(dynamicParameter); , interval); 


        Then call it as createInterval(funca,dynamicValue,500); Obviously you can extend this for more than one parameter. And, please, use more descriptive variable names. :)






        share|improve this answer













        Courtesy of @tvanfosson:



        You probably want to have a function that creates the interval timer for you. Pass in the parameter to the function so its value is captured in the function closure and retained for when the timer expires.



        function createInterval(f,dynamicParameter,interval) setInterval(function() f(dynamicParameter); , interval); 


        Then call it as createInterval(funca,dynamicValue,500); Obviously you can extend this for more than one parameter. And, please, use more descriptive variable names. :)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 25 at 18:31









        Alec AlameddineAlec Alameddine

        3,8804 gold badges12 silver badges40 bronze badges




        3,8804 gold badges12 silver badges40 bronze badges



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55344331%2fhow-to-pass-the-dynamic-variable-to-setinterval-method%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript