您好建立离子应用程序,获取连接的WiFi信息并将其发送到firebase
此功能正常工作 但是我想要一次点击按钮来循环这个功能,每30秒发送一次值,如果再次点击按钮就会停止循环。
有人可以教我怎么做吗?
按钮代码
<button
class="button icon-left ion-radio-waves button-positive inactive b_resize"
ng-click='getWifiInfo();'>Send Wifi info
</button>
功能代码
$scope.getWifiInfo = function() { //get wifiinfo
function success(results) {
$scope.wifiinfo=results;
$scope.$apply();
$scope.currentDate = $filter('date')(new Date(),'EEEE,d MMMM, y');
$scope.currentTime = $filter('date')(new Date(),'h:mm:ss a');
fireBaseData.refUser().child($scope.user_info.uid).child("wifiinfo-record").child($scope.currentDate).child($scope.currentTime).push({
//wifi data send to wifiinfo-record
SSID: $scope.wifiinfo.SSID,
MacAddress:$scope.wifiinfo.BSSID,
SignalStrength: $scope.wifiinfo.Rssi,
type:"record",
});
};
function err(e) {
console.log(JSON.stringify(e));
};
WifiInfo.getWifiInfo(success,err);
}
答案 0 :(得分:3)
您正在寻找setInterval
function foo(){
console.log('function is being called')
}
var interval = setInterval(foo, 30000);
并阻止你做:
clearInterval(interval);