Page 1 of 1

Getting value from Ionic global variable

Posted: Mon Apr 23, 2018 8:55 pm
by Alan Smith

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?


Getting value from Ionic global variable

Posted: Tue Apr 24, 2018 9:14 am
by Serhii Kulibaba

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