Skip to content

Instantly share code, notes, and snippets.

@dyaa
Created February 17, 2015 15:58
Show Gist options
  • Save dyaa/a8020bbd6a2b43300b9c to your computer and use it in GitHub Desktop.
Save dyaa/a8020bbd6a2b43300b9c to your computer and use it in GitHub Desktop.
Using favico.js with AngularJS - Working demo is on http://lab.ejci.net/favico.js/example-angular/.
angular.module('app.controllers', ['favico.service']).controller('homeCtrl', ['$scope', 'favicoService', /**
* Home view controller
* @param {Object} $scope
*/
function($scope, favicoService) {
//initial value
$scope.count = 3;
//badge +1
$scope.plusOne = function() {
$scope.count = $scope.count + 1;
favicoService.badge($scope.count);
};
//badge -1
$scope.minusOne = function() {
$scope.count = ($scope.count - 1 < 0) ? 0 : ($scope.count - 1);
favicoService.badge($scope.count);
};
//badge reset (count will be preserved)
$scope.reset = function() {
favicoService.reset();
};
//init value
favicoService.badge($scope.count);
}]);
/**
* Simple favicon service
*/
angular.module('favico.service', []).factory('favicoService', [
function() {
var favico = new Favico({
animation : 'fade'
});
var badge = function(num) {
favico.badge(num);
};
var reset = function() {
favico.reset();
};
return {
badge : badge,
reset : reset
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment