comaster mooko6l comaster mooko6l - 1 year ago 52
AngularJS Question

How to loop this function in every 30 second?

Hello building ionic app that get a connecting wifi info and send it to firebase

this function work normally
but I want 1 time button click to loop this function to send value in every 30 second and if button click again will stop loop.

can someone teach me how to do please?

button code

class="button icon-left ion-radio-waves button-positive inactive b_resize"
ng-click='getWifiInfo();'>Send Wifi info

function code

$scope.getWifiInfo = function() { //get wifiinfo
function success(results) {


$scope.currentDate = $filter('date')(new Date(),'EEEE,d MMMM, y');
$scope.currentTime = $filter('date')(new Date(),'h:mm:ss a');


//wifi data send to wifiinfo-record
SSID: $scope.wifiinfo.SSID,
SignalStrength: $scope.wifiinfo.Rssi,


function err(e) {

Answer Source

You're looking for setInterval

function foo(){
    console.log('function is being called')

var interval = setInterval(foo, 30000);

and to stop it you'll do: