How to create remember me in angular js

    Create a service to add/remove cookie
    define(
        ['app'],
        function (app) {
            app.factory('$remember', function() {
                function fetchValue(name) {
                    var gCookieVal = document.cookie.split("; ");
                    for (var i=0; i < gCookieVal.length; i++)
                    {
                        // a name/value pair (a crumb) is separated by an equal sign
                        var gCrumb = gCookieVal[i].split("=");
                        if (name === gCrumb[0])
                        {
                            var value = '';
                            try {
                                value = angular.fromJson(gCrumb[1]);
                            } catch(e) {
                                value = unescape(gCrumb[1]);
                            }
                            return value;
                        }
                    }
                    // a cookie with the requested name does not exist
                    return null;
                }
                return function(name, values) {
                    if(arguments.length === 1) return fetchValue(name);
                    var cookie = name + '=';
                    if(typeof values === 'object') {
                        var expires = '';
                        cookie += (typeof values.value === 'object') ? angular.toJson(values.value) + ';' : values.value + ';';
                        if(values.expires) {
                            var date = new Date();
                            date.setTime( date.getTime() + (values.expires * 24 *60 * 60 * 1000));
                            expires = date.toGMTString();
                        }
                        cookie += (!values.session) ? 'expires=' + expires + ';' : '';
                        cookie += (values.path) ? 'path=' + values.path + ';' : '';
                        cookie += (values.secure) ? 'secure;' : '';
                    } else {
                        cookie += values + ';';
                    }
                    document.cookie = cookie;
                }
            });
        }
    );
    Use this service in your login controller like this
        app.controller("LoginCtl", ["$scope", '$remember', function($scope, $remember){
            $scope.remember = false;
            if ($remember('username') && $remember('password') ) {
                $scope.remember = true;
                $scope.username = $remember('username');
                $scope.password = $remember('password');
            }
            $scope.rememberMe = function() {
                if ($scope.remember) {
                    $remember('username', $scope.username);
                    $remember('password', $scope.password);
                } else {
                    $remember('username', '');
                    $remember('password', '');
                }
            };
        }]);
    and remember me checkbox look like this
    <label>
    <input type="checkbox" name="remember" data-ng-click="rememberMe()" data-ng-model="remember"> &nbsp; Remember Me
    </label>
    5
    Average: 5 (1 vote)