javascript - AnulgarJS - Object parameters in service not changing -


i'm having troubles services in angular.

basically have service use constant class user specific parameters, store these in variables read values cookie.

this service:

shoutapp.service('userconfig', function (userservice, config) { this.user_id = $.cookie('shoutuserobj')._id; this.user_username = $.cookie('shoutuserobj').username; this.user_password = $.cookie('shoutuserobj').password; this.user_joindate = $.cookie('shoutuserobj').joindate; this.user_twitter = $.cookie('shoutuserobj').twitter; this.user_facebook = $.cookie('shoutuserobj').facebook; this.user_google = $.cookie('shoutuserobj').google;  this.refreshuserobj = function (callback) {     console.log("starting refresh");     //this function retrieves new user data     userservice.requestuserobj($.cookie('shoutuserobj')._id, function (code, userobj) {         if (code === config.code_ajax_success) {             //here delete old cookie , set new 1 same name             $.removecookie('shoutuserobj');             $.cookie.json = true;             $.cookie('shoutuserobj', userobj, { path: '/', expires: 7 });             //when log new values of cookie @ point changed         }     }); } }); 

i tried storing these in object, every time change paramters change inside class ( when log out new variables in refresh function, changed, when try access them controller through return values, not changed).

example controller:

shoutapp.controller('profilecontroller', function ($scope, config, userconfig) {   console.log("username: " + userconfig.user_username);   //this value allways stays same, when changed cookie }); 

my goal changed paramteres in controllers use user service, how can achieve this?

would thankful help!

services singletons, therefore values of userconfig properties have values had when service initialized.

in service, use function if want retrieve new value each time

    this.getuser_username = function() {         return $.cookie('shoutuserobj').username;     } 

instead of property

    this.user_username = $.cookie('shoutuserobj').username; 

then example controller be:

shoutapp.controller('profilecontroller', function ($scope, config, userconfig) {   console.log("username: " + userconfig.getuser_username());   //this return current value of cookie }); 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -