Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. var myApp = angular.module("myApp", ['']);
  2.  
  3. myApp.factory("DataService", ["$http", function ($http){
  4. var getData = function(callback){
  5. var url = 'api-url-returns-json';
  6. $http.get(url).success( function(response) {
  7. callback(response);
  8. });
  9. }
  10. return {
  11. getDashboardData: getData
  12. }
  13. }]);
  14.  
  15. myApp.factory("ClockProvider", ["$interval", function ($interval){
  16. var time = null;
  17. var runOnTick = function(tick, callback){
  18. var myClock = $interval(function(){
  19. time = new Date();
  20. m = time.getMinutes();
  21. s = time.getSeconds();
  22. var array = tick;
  23. var arrayLength = array.length;
  24. for (var i = 0; i < arrayLength; i++) {
  25. var value = array[i];
  26. if (value == m) {
  27. callback();
  28. }
  29. }
  30. }, 2000);
  31. }
  32. return {
  33. run: runOnTick
  34. }
  35. }]);
  36.  
  37. myApp.controller("dashboardController", ["$scope", "DataService", "ClockProvider", function ($scope, DataService, ClockProvider){
  38. DataService.getDashboardData(function(data){
  39. $scope.dashboard = data;
  40. });
  41. var intervals = ["0", "30"];
  42. ClockProvider.run(intervals, function(){
  43. DataService.getDashboardData(function(data){
  44. $scope.dashboard = data;
  45. });
  46. });
  47. }]);
  48.  
  49. <html ng-app="myApp">
  50. </head></head>
  51. <body>
  52. <div ng-controller="dashboardController">
  53. <span>{{ dashboard.status }}</span>
  54. </div>
  55. </body>
  56. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement