-
Notifications
You must be signed in to change notification settings - Fork 3k
Preventing state reload on URL change #427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
For anyone interested, the solution was: angular.module('Shared').service('location', function($location, $rootScope) {
$location.skipReload = function () {
var un = $rootScope.$on('$stateChangeStart', function (event) {
event.preventDefault();
un();
});
return $location;
};
return $location;
}); |
Hi, I need this exact feature. Your first solution work as expected : the URL is updated without reload the view. Your second one with ui-router doesn't work as expected : it doesn't reload the view but the URL update is canceled. So neither reload ans update occurs. Did you miss something in your solution ? |
Yeah, the code above took advantage of a bug in ui-router that since got fixed, I didn't realise it at the time. We're now using this, which also uses the decorator pattern rather than adding a new service: function locationDecorator($location, $rootScope) {
var skipping = false;
$rootScope.$on('$locationChangeSuccess', function(event) {
if (skipping) {
event.preventDefault();
skipping = false;
}
});
$location.skipReload = function() {
skipping = true;
return this;
};
return $location;
}
angular.module('Shared').config(['$provide', function($provide) {
$provide.decorator('$location', locationDecorator);
}]); and can be used as $location.skipReload().path('/new/path').replace(); |
If my understanding of |
@roryf your new version to skip reload is not working - view still reloads after calling $location.path. At least for me. This is the event call order I have: As far as I understand, when we preventDefault on "$locationChangeSuccess" ui-router already did the work. |
Probably an event-firing order issue. We'll have to figure out an alternative solution. |
I got the same use case as described above (going from route "/new" to "/{id}") I hope it will be possible to have a consistent way to do this without reloading the controller. = +1 |
has anyone found a new solution to the problem? |
this is really bad, so far i can't find any solution yet to this problem. :( |
instead of using the $location I used the $urlMatcher to get the state from a url and change the state instead of the url. the good part of this approach is that the ui-router doesn't get lost after the url change I created a provider to give you the idea, it setup the routing with a collection, and search the route on it, maybe it helps: |
I'll have a permanent fix for this shortly. Just finishing testing. |
Fixed in c72d8ce. See example code here: Lines 212 to 242 in c72d8ce
|
Sorry, I still cannot figure out how to do this. How did the fix help this out? What is the current way of changing the URL without a reload? |
Forked ui-router, created a release to play with and tried out the deferIntercept(); stuff. Used the example given in the ngdoc but not quite sure if it's working correctly. The initial location change is deferred correctly and doesn't update until the Either way, I don't believe the The question above I believe is to stop the reloading of the controller/reloading of the view (ng-repeat re-running when something like a routeParameter is changed. If you have an ng-repeat with say 1,000 items and change a stateParam. Your may just want to just hide/show a tab, but all 1,000 items are going to get ng-repeated every time. |
I'm getting this to work in a modal service via:
|
@intellix Did you ever find anything out about this issue? I for the life of me can't figure out a way around this. |
@roryf thanks for the decorator. This is fixed version that uses $delegate:
|
@roryf, thanks for your decorator solution! I can confirm it works with ui-router 0.2.13 and angular 1.2.14. |
This seems to be a poorly documented option of the //change state without refreshing everything
$state.go('my-state', { id: myId }, { notify: false }); |
@heygrady That worked for me |
@heygrady Thanks for the tip, worked great! |
For some reasons, it didn't work for me.
I hope it helps someone. Note: I'm using angularjs 1.2.7 and ui-router 0.0.1 (I know it's old). |
This will allow what you're after. You can disable the notify on a link so the URL changes but doesn't reload your controller: #1875 |
Hello, @nateabele It seems your code break the replace function
Am I wrong ? |
@roryf legend mate! Worked on angular 1.3.16 & angular-ui-router 0.2.15. |
@jeremieca Show me. |
@nateabele Thanks, it solved. I made a mistake :) Sorry. |
@roryf Inside of decoration function must be used
|
Though Created lib from that: https://github.com/anglibs/angular-location-update |
@roryf @garmoshka-mo Great work! However, |
I currently use the following code to prevent my route, and therefore controller, being reloaded when I update the $location:
along with:
Can I achieve the same behaviour with ui-router?
I tried simply replacing
$route
above with$state
but this still resulted in a state change. My use case is I only have 'new' and 'edit' states which are exactly the same, when a user saves within the 'new' state I want to update the URL to include the saved id but not reload the view.The text was updated successfully, but these errors were encountered: