Blank Angular 1.4.8 project
A starter template for angular1.4.8 fiddles
HTML
<div ng-app="TestApp" ng-controller="TestController">
</div>
JavaScript
var app = angular.module('TestApp', []);
app.controller('TestController', function($scope, $timeout, LocationService) {
console.log('app init');
//-- on checkbox change and/or app init;
var trackLocation = true;
if (trackLocation) {
LocationService.start();
//-- imitate them turning the service off
$timeout(function() {
console.log('stop tracking location');
LocationService.stop();
},10000);
}
});
app.service('LocationService', function($interval) {
var int;
return {
start: function() {
int = $interval(this.saveLocation,3000);
},
stop: function() {
$interval.cancel(int);
},
saveLocation: function() {
console.log('save location');
}
}
});