Created
April 17, 2015 08:39
-
-
Save geraldvillorente/65dae6173b64426f6e51 to your computer and use it in GitHub Desktop.
Drupal auto refresh using AngularJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function ($, Drupal) { | |
Drupal.behaviors.refresh = { | |
attach: function(context, settings) { | |
var app = angular.module('app', []); | |
app.controller('appController', function($scope, Poller) { | |
$scope.data = Poller.data; | |
}); | |
app.run(function(Poller) {}); | |
app.factory('Poller', function($http, $timeout) { | |
var data = { | |
response: {}, | |
calls: 0 | |
}; | |
var poller = function() { | |
$http.get(settings.url.json).then(function(r) { | |
data.response = r.data; | |
data.calls++; | |
$timeout(poller, 1000); | |
}); | |
}; | |
poller(); | |
return { | |
data: data | |
}; | |
}); | |
} | |
}; | |
})(jQuery, Drupal); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment