Skip to content

Instantly share code, notes, and snippets.

@geraldvillorente
Created April 17, 2015 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geraldvillorente/65dae6173b64426f6e51 to your computer and use it in GitHub Desktop.
Save geraldvillorente/65dae6173b64426f6e51 to your computer and use it in GitHub Desktop.
Drupal auto refresh using AngularJS
(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