Angularjs - multiple tabs in same browser

2

I'm using angularJS in my Node application. When I try to open another tab also with my application in the same browser (or open another instance of the same browser) I get this error:

s:1 Uncaught SyntaxError: Unexpected token u in JSON at position 0(anonymous function) @ utils.js:14
angular.js:13236 SyntaxError: Unexpected token u in JSON at position 0
at Object.parse (native)
at new MyController (http://meuProjeto/my.controller.js:8:28)
at Object.invoke (http://meuProjeto/js/libs/angular-1.5.0/angular.js:4604:19)
at extend.instance (http://meuProjeto/js/libs/angular-1.5.0/angular.js:9855:34)
at nodeLinkFn (http://meuProjeto/js/libs/angular-1.5.0/angular.js:8927:34)
at compositeLinkFn (http://meuProjeto/js/libs/angular-1.5.0/angular.js:8226:13)
at publicLinkFn (http://meuProjeto/js/libs/angular-1.5.0/angular.js:8106:30)
at http://meuProjeto/js/libs/angular-1.5.0/angular.js:1696:27
at Scope.$eval (http://meuProjeto/js/libs/angular-1.5.0/angular.js:16820:28)
at Scope.$apply (http://meuProjeto/js/libs/angular-1.5.0/angular.js:16920:25)(anonymous function) @ angular.js:13236

In my script utils.js on line 14 has the following command:

var param = JSON.parse(window.sessionStorage.param);

I know it's very generic, but I'm a newbie in WEB development and I'm posting this hope that someone has had the same problem (or something similar) and can guide me! I have no idea where to start looking for a solution, so I posted it too.

If necessary, I can add some information that is relevant and I have not put it here.

Thank you in advance!

    
asked by anonymous 06.07.2016 / 17:02

1 answer

2

sessionStorage belongs exclusively to the browser session, which is linked to the page.

If you want to share content between two or more tabs / windows, use localStorage .

Implementation example:

app.factory('userService', ['$rootScope', function ($rootScope) {
    var service = {
        model: {
            name: '',
            email: ''
        },

        SaveState: function () {
            sessionStorage.userService = angular.toJson(service.model);
        },

        RestoreState: function () {
            service.model = angular.fromJson(sessionStorage.userService);
        }
    }

    $rootScope.$on("savestate", service.SaveState);
    $rootScope.$on("restorestate", service.RestoreState);

    return service;
}]);

(source: link )

Below is a list of services that can help you:

06.07.2016 / 17:06