Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I'm usnig AngularJs 1.2.25. I have a route config:

$routeProvider.when(
    '/config-root',
    { 
        templateUrl: configRootTemplate,
        controller: "ClientConfig",
    }
).when(
    '/config-action/:action/:_id',
    { 
        templateUrl: configActionTemplate, 
        controller: "ClientConfigAction",
    }
).otherwise({redirectTo: '/'});

In the ClientCOnfig controller, I have a $scope.listConfig variable binding with template for creating, updating list of config.

Everything ok when the first time I visit "config-root" route, I can generate, update... the list.

But when the second time or so far, $scope.listConfig change properly when generate list, update... but the template does not change.

I think when I visit that route again, a new instance of $scope created and does not binding with the template.

How can I fix it?

share|improve this question

You can use rootScope to preserve the value for the next time.

change that $scope to $rootScope and access that when ever its required.

If you don't want to pollute the $rootScope you can just store the values in a localStorage as a string and fetch it when ever its required.

// To store the value 
localStorage['config'] = JSON.stringify(someObj)  
// To fetch the value 
var myConfigObj = JSON.parse(localStorage['config'])
share|improve this answer
    
Thank you for your answer, but I think this solution is not my need. Because $rootScope is global, not good for managing variables. If using localStorage, I can not use data binding of angularjs. – ronin1184 Sep 21 '14 at 14:05
    
Than you can use constants which you can inject into to any controller. Refer angularjs constants. – siddhartha Sep 21 '14 at 16:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.