opitzconsulting / jquery-mobile-angular-adapter

jquery mobile angular adapter
MIT License
517 stars 114 forks source link

Controller does not reload after routing is performed to the same partial template #188

Closed mieszko4 closed 11 years ago

mieszko4 commented 11 years ago

The problem: I have defined 3 routes with two partial templates assigned to the same Controller TestCtrl. When uri is changed through $location.path(), controller does not reload if new uri has the same templateUrl defined.

Code: Please take a look at the code: http://plnkr.co/edit/6HfpflBYVn0Pf2oIa5ov Since it requires rooting I uploaded the same code to:

  1. Clean version: http://chmura.org/pages/jqmaa/index-clean.html
  2. Version with JQMAA: http://chmura.org/pages/jqmaa/index-JQMAA.html

How to reproduce:

  1. Open developer tools
  2. index-clean.html Click on links from left to right one by one. Each click will generate 'init' in console.log. This works as expected.
  3. index-JQMAA.html Click on links from left to right one by one. 'init' will generate only when change happens between two routes of different partial templates defined. Uri changes visible in location bar are correct and fade effect are visible after each uri change (as expected).

The problem is that controller does not reload in the same way as with clean version.

tbosch commented 11 years ago

Hi, I uploaded your example to plncr.co, so I can modify it: http://plnkr.co/edit/2eZ9k1B2yyM9CK83X3D5?p=preview

In contrast to angular, the adapter caches pages/views. The caching is a feature of jquery mobile and can be controlled using the data-dom-cache attribute, see here: http://jquerymobile.com/demos/1.2.0/docs/pages/page-cache.html. All views defined in the index.html are cached by default. External views are only cached until navigating to another view, unless it's the same view. This caching is good thing for performance, as angular does not need to recompile the views, so you could turn it on by adding data-dom-cache=true to every partial: http://plnkr.co/edit/i5td2AuZsGPOfowTcQDa?p=preview. Now every controller is created only once, when the view is visited for the first time.

If you want to update the view using the data from the route, use the new onActivate property of routes (https://github.com/tigbro/jquery-mobile-angular-adapter#navigation-and-routes). Here is a modified version of your code showing how to access route params: http://plnkr.co/edit/MWQRkxNvYFezPJAybaMz?p=preview

Hope this helps, Tobias

mieszko4 commented 11 years ago

Many many thanks! This has definitively helped me!