javascript - Share updated variable with factory (variable scope) -


i share updated variable (updated function) through factory (angularjs)

i have following factory:

apptspsrv.factory('shared', function(db) {      var entities;      var getentities = function(){         db.query('getentities', function(err, doc) {             if (err) {                 console.log(err);             } else {                 entities = doc.rows;             }         });     };     getentities();      return {         getentities: function() {             return entities;         }     }  }); 

when call factory's function controller 'undifined':

console.log(shared.getentities()); 

why , how can fix this?


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -