Saturday 15 May 2010

angularjs - Unable to access $rootScope in factory -



angularjs - Unable to access $rootScope in factory -

i having unusual error angular.js using version 1.2.26. below code, not able access properties set in $rootscope. when log $rootscope can see properties. not able access properties.

angular .module('ids.factories', []) .factory('storefactory', ['$rootscope', function ($rootscope) { console.log($rootscope);//this defined , can see store property console.log($rootscope.store);//this seems undefined homecoming { get: function (key, callback) { homecoming $rootscope.store.get(key, callback) }, save: function (key, data, callback) { $rootscope.store.save({ key: key, value: info }, callback); }, remove: function (key) { $rootscope.store.remove({key: key}); } } }]);

this error depends on how developer tools of browser working. tassekatt said in сomment, console.log() got called before variable initialized. later in console, see reference evaluated code. developer - tool gives hint little bluish sign besides console.log entry. (you see in screenshot, too) greetings!

angularjs angularjs-scope

No comments:

Post a Comment