Alan Smith
Posts: 0
Joined: Tue Jun 10, 2014 4:59 pm

Getting value from Ionic global variable

I have a global variable set via a model.

Image

Its in JSON format.

I need to get to the value of the JSON object, not for the UI, but for custom code.

This is the value I am saving in the model variable JSON

{"expiry":"2018-04-23T21:51:46.816+01:00","merchantSessionKey":"415E555465-8475-4498-88E7-7A0703nhE4B5E"}

How do i get the merchantSessionKey from the model?

I'm setting the variable via this, from a service response:

Code: Select all

     var MerchantKey_scope = $scope.MerchantKey; 
     _.set(MerchantKey_scope, 'MKey', success.data.requestParams); 
     MerchantKey_scope = success.data; 
     $scope.MerchantKey = MerchantKey_scope; 

When i try this $scope.MerchantKey, i get [object object]

I've tried $scope.MerchantKey.merchantSessionKey

I've tried $scope.MerchantKey['merchantSessionKey']

I've tried $scope.MerchantKey.MKey

Ive tried json parse

I've tried json stringify

What am i doing wrong?

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Getting value from Ionic global variable

Hello Alan,

Please clarify, if you created the global scope variable "merchantKey" on the index page, with the type "MerchantKey"?

Please create it.

After that, you'll be able to get all it's properties, like MKey:
pre$scope.merchantKey.MKey;/pre

Return to “Issues”