-
Notifications
You must be signed in to change notification settings - Fork 248
ng-view contents reevaluated for the same route #837
Comments
Yes, it is similar issue, but the problem, in this case is even more general: I would expect that the parent view does not reload when the child view changes. e.g. in the following case, when we want to be able not only to change recipe id, but also how it is displayed.
|
What you describe should not be happening. I created a simple example, but unable to reproduce what you're seeing: class MyAppModule extends Module {
MyAppModule() {
value(RouteInitializerFn, (r, views) {
views.configure({
'recipes': ngRoute(
path: '/recipes',
view: 'recipes.html',
mount: {
'view': ngRoute(
path: '/:recipeId/view',
view: 'view.html'),
'edit': ngRoute(
path: '/:recipeId/edit',
view: 'edit.html')
})
});
});
type(CountingCtrl);
factory(NgRoutingUsePushState,
(_) => new NgRoutingUsePushState.value(false));
}
}
int __count = 0;
@NgController(selector: '[counting-ctrl]', publishAs: 'ctrl')
class CountingCtrl {
final int count = __count++;
} recipes.html <h1>Recipes</h1>
<ul>
<li><a href="#/recipes/123/view">Recipe 123</a>
<li><a href="#/recipes/124/view">Recipe 124</a>
<li><a href="#/recipes/125/view">Recipe 125</a>
<li><a href="#/recipes/126/view">Recipe 126</a>
</ul>
<div counting-ctrl>count: {{ctrl.count}}</div>
<ng-view></ng-view> view.html <h2>View</h2>
<div counting-ctrl>count: {{ctrl.count}}</div> When I click on the links I see that the count inside Can you share a repro? |
We made some investigations and now we understand what's happening. In fact, your case works properly, however our case is slightly different. Our application is dynamically built from components, the organization of components is read from a server in an AJAX call at the start of the application. Based on the JSON response we then configure our router and also particular views must also be built according to this JSON result. So when configuring routes, we do not have static files with HTML templates that we could pass as views. Instead, we create just one template, dyn_view.html, with a dynamic-view component inside. The dynamic-view's responsibility is to put to the DOM actual contents. How the dynamic-view knows what to put inside? It looks at the JSON data passed to it through additional routing parameters, which are added "behind the scenes". And these additional parameters added to the route event cause the parent view to be reloaded each time even when only child view changes. We do not know how to solve this. Ideally, we would like to be able to pass a template during route configuration instead of just a template URL, e.g.
dyn_view.html
recipes.dart
view.html
|
This issue now probably can be closed: #425 solves all the problems and the workaround described above is no longer needed. Thanks a lot! |
Thanks for the feedback |
I have the following problem: the application has a static top panel which contains a horizontal main menu. The central area contains ng-view which changes accordingly to the selection of the main menu item. In the ng-view, for some of the main menu items, we want to display another navigation panel with a vertical sub-menu and a detail panel. The detail panel is another ng-view and changes accordingly to the selection of the sub-menu item.
E.g. for recipe book application if want to have some main menu items like: home, recipes, gallery, contact, and for recipes I have e.g. list of recipes
Lines represent ng-views:
What I want to achieve is an animation effect on the sub-menu when going between different recipes. The problem is that the sub-menu is rendered from scratch when changing a recipe. This is strange, as it does not need to change, because the part of the url responsible for picking up recipes.html does not change. In AngularJS, as expected, the sub-menu is not rendered again. Is this a bug in AngularDart, or the expected behavior?
The text was updated successfully, but these errors were encountered: