Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var myApp = angular.module("myApp", ['']);
- myApp.factory("DataService", ["$http", function ($http){
- var getData = function(callback){
- var url = 'api-url-returns-json';
- $http.get(url).success( function(response) {
- callback(response);
- });
- }
- return {
- getDashboardData: getData
- }
- }]);
- myApp.factory("ClockProvider", ["$interval", function ($interval){
- var time = null;
- var runOnTick = function(tick, callback){
- var myClock = $interval(function(){
- time = new Date();
- m = time.getMinutes();
- s = time.getSeconds();
- var array = tick;
- var arrayLength = array.length;
- for (var i = 0; i < arrayLength; i++) {
- var value = array[i];
- if (value == m) {
- callback();
- }
- }
- }, 2000);
- }
- return {
- run: runOnTick
- }
- }]);
- myApp.controller("dashboardController", ["$scope", "DataService", "ClockProvider", function ($scope, DataService, ClockProvider){
- DataService.getDashboardData(function(data){
- $scope.dashboard = data;
- });
- var intervals = ["0", "30"];
- ClockProvider.run(intervals, function(){
- DataService.getDashboardData(function(data){
- $scope.dashboard = data;
- });
- });
- }]);
- <html ng-app="myApp">
- </head></head>
- <body>
- <div ng-controller="dashboardController">
- <span>{{ dashboard.status }}</span>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement