-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Need to be able to update the $location.hashSearch without triggering route change. #354
Comments
The current thinking is that we reload the page on each URL change to make sure that there is no difference between navigating to a URL and opening a link. However this extreme approach is causing issues. Proposal
Just like now each route will be associated with a URL hashPath, Controller as well as template. If the URL changes which will activate new route, we will instantiate a new controller and then call the This approach will mean that unless the developer puts extra code in the Examplefunction MyApp($route) {
$route.when('/Book/:bookId', {template:'rsrc/book.html', controller:BookCntl});
$route.when('/Book/:bookId/ch/:chapterId', {template:'rsrc/chapter.html', controller:ChapterCntl});
}
function BookCntl(){
// Executes on new instance -> when hashPath changes
}
BookCntl.prototype = {
$render: function(properties){
// Executes multiple times on same instance per URL change as long as hashPath remains same
}
}
function ChapterCntl(){
}
ChapterCntl.prototype = {
$render: function(properties){
}
} |
Is there an implicit $eval already in the calling code of render or would this require an explicit call to $eval? |
In angular all calls have always in implicit call to $eval. The only place where one has to call eval is at the boundries, for example when one is writing their own widget. So no need for $eval it is automatic. Do you have a better name for this method? I am not sure it should be prefixed with $, but I am thinking yes, since it is angular API that you, as a developer, have to implement. |
How about creating new controller only when its different than the current one. (not always when hashPath change). Using your example: function MyApp($route) {
$route.when('/Book/:bookId', {template:'rsrc/book.html', controller:BookCntl});
$route.when('/Book/:bookId/ch/:chapterId', {template:'rsrc/chapter.html', controller:ChapterCntl});
} When you open |
I'm not too crazy about this magic method on the controller. Can't we enhance the route declaration instead?
|
@IgorMinar, enhancing route declaration is certainly a possibility. By I wonder if the extra level of indirection is worth it? What is your objection to implementin well defined methods. |
I think that |
you have to come up with |
What about introducing BDD-like events on controllers, such as beforeAll, beforeEach, afterEach, afterAll? beforeAll/afterAll are lifetime events for the route. beforeEach/afterEach are lifetime events for the current hashstate. The logic you would have put in $render would go into beforeEach. |
Full lifecycle, sounds like a good idea. Do you know the exact events you are looking for? |
Any update to this issue ? Currently we destroy the old route and scope always when $location.hashPath / $location.hashSearch changes. |
Well there are two possible solutions that were already implemented:
All of us agreed that neither is a particularly good solution. Misko's solution introduces magical method and convention-over-configuration as well as different behavior of controllers depending on weather they are used with $route or ng:controller. Mine suffers from having two different execution paths in controllers for a given url depending on weather you are changing routes or not. The approach that requires use of events or event bus sounds like the most ideal, but is also the hardest to implement right now because we don't have any infrastructure for it yet. |
In order to avoid unnecesary route reloads when just hashSearch part of the url changes, it is now possible to disable this behavior by setting reloadOnSearch param of the route declaration to false. Closes angular#354
In order to avoid unnecesary route reloads when just hashSearch part of the url changes, it is now possible to disable this behavior by setting reloadOnSearch param of the route declaration to false. Closes angular#354
In order to avoid unnecesary route reloads when just hashSearch part of the url changes, it is now possible to disable this behavior by setting reloadOnSearch param of the route declaration to false. Closes angular#354
We don't want reload the entire controller and template when the user changes the search criteria.
This will allow us to maintain the current state of the current controller, while making the page book-markable.
The text was updated successfully, but these errors were encountered: