angularjs - Javascript variable becomes undefined when passed as an argument to a function -



angularjs - Javascript variable becomes undefined when passed as an argument to a function -

i have angular programme service holds map of current value (very much context). @ different places in programme phone call service currentvalue of something. service called crsviewcontext , methods quite simple

.service('crsviewcontext', function () { var currentinstances = {}; this.setcurrent = function (domain, instance) { currentinstances[domain] = instance; console.log('viewcontext setcurrent: ' + domain); console.dir(instance); }; this.getcurrent = function (domain) { console.log('viewcontext getcurrent: ' + domain); console.dir(currentinstances[domain]); homecoming currentinstances[domain]; }; this.resetcurrent = function (domain) { console.log('viewcontext resetcurrent: ' + domain); currentinstances[domain] = null; }; });

in controller pass crsviewcontext argument , that

.controller('myctrl', function (crsviewcontext) { var n = crsviewcontext.getcurrent ('realestate'); console.log ("get current real estate"); console.dir (n); console.log ("current real estate id: "+n.id); });

however lastly log gets undefined though in console can see prior statement returning object defines id , value

something javascript and/or restangular since utilize restangular retrieve object. on side note if access console, have no problem getting id

n=$('#wrapper').injector().get('crsviewcontext').getcurrent('realestate').id;

returns 3 console

thanks in advance

pascal

after much poking removed phone call $object made on variable before in code. restanglar returns promises , understanding calling $object on promise guarantee value returned not. keeping variables promises seems work. don't understand why –

javascript angularjs

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -