javascript - Pass object id to session storage -


i have simple function post selected object id session storage works numbers when change word dose not work, idea why , how fix it?

i thought fine both string, can see function @ bottom parse json, dont see why works numbers ?

code

$scope.productsandformats = [{     "name": "name 1",     "format": [{         "fname": "test (roadside temp)",         "id": "roadside"     }, {         "fname": "test sheet",         "id": "2"     }, {         "fname": "wrap test (digital)",         "id": "3"     }] }, {     "name": "name 2,     "format": [{         "fname": "2 test",         "id": "4"     }, {         "fname": "test live (digital)",         "id": "5"     }] }; $scope.producttypechange = function() {     $scope.formats = $scope.productsandformats.find(ps => ps.name === $scope.formdata.producttype.name)         //ng-change     $scope.myfunc = function() {         var jsonitem = json.parse($scope.formdata.formattype.id);         sessionstorage.setitem('format', jsonitem);     } } }); 

i error in inspector

syntaxerror: unexpected token r in json @ position 0 @ json.parse ()

the id parsing isn't json, that's why you're getting error.

in point of fact whole scope object javascript object, not json (which text format).

the id string "roadside", if it's json string it'd "{ \"key\": \"value\" }". fact it's missing opening brace tells parser it's wrong.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

android - IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling -