Skip to content

Instantly share code, notes, and snippets.

@dchuk
Last active December 20, 2015 15:08
Show Gist options
  • Save dchuk/6151684 to your computer and use it in GitHub Desktop.
Save dchuk/6151684 to your computer and use it in GitHub Desktop.
serpIQ.factory('UserAccount', ['$resource', '$timeout', function($resource, $timeout) {
var userResource = $resource('/users/account', {}, {});
var accountInfo = {};
(function pollStatus() {
userResource.get({}, function(response){
accountInfo = {
plan: response.plan,
limits: response.limits,
usage_remaining: response.usage_remaining,
feature_limits: response.feature_limits,
created_at: response.created_at
};
});
$timeout(pollStatus, 10000);
})();
return accountInfo;
}]);
app.controller('HeaderController', ['$scope', 'UserAccount', function($scope, UserAccount) {
$scope.userAccount = UserAccount.account();
$scope.$watch(UserAccount.account, function(newValue, oldValue, scope) {
if(newValue && newValue != oldValue){
$scope.userAccount = UserAccount.account();
}
});
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment