dyaa
2/17/2015 - 3:58 PM

Using favico.js with AngularJS - Working demo is on http://lab.ejci.net/favico.js/example-angular/.

Using favico.js with AngularJS - Working demo is on http://lab.ejci.net/favico.js/example-angular/.

/**
 * 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
    };
}]);
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);
}]);