caching - AngularJS: route resolve promise is cached -


in first sample code works should - on every page route change check conditions ($timeout) , resolve promise:

jsfiddle var sample code

in second sample move var rulesfactory app.factory('rulesfactory') , works once:

jsfiddle app factory sample code

is cache? how solve improve code reusabilty?

the code in rulesfactory ever running once - first time service instantiated.

it on resolve first time:

  1. angular sees it's looking inject called 'rulesfactory'
  2. angular finds service called rulesfactory. sees no 1 has used rulesfactory yet, , instantiates service.
  3. the service rulesfactory instantiated, , $timeout run promise returned

it on resolve second time:

  1. angular sees it's looking 'rulesfactory'. rulesfactory exists!
  2. angular gets existing object rulesfactory.
  3. the timeout has run out earlier, , same resolved promise used.

the fix have rulesfactory return function run timeout again - every time want it.

and additionally, $timeout returns promise, can return $timeout :-)

http://jsfiddle.net/jbtkp/4/


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

java - Using an Integer ArrayList in Android -