In my application I use routeUpdate
to check if the $location.search
string has changed and navigate accordingly in my view.
Like so.
$scope.$on('$routeUpdate', function(next, current) {
var slide_key = $location.search().slide_key;
if (slide_key)
$scope.go_to_slide(slide_key);
});
Also keep in mind that I use reloadOnSearch
false to not reload the controller.
Usually I trigger this by changing the $location.search
and works fine
Everything works fine but there is a case where I want to trigger this behavior without changing the search parameters.
I tried to just change the search parameters to again the same value -> No luck.
If I change it to another value then the routeUpdate
fires and everything works ok.
So how can I manually trigger the routeUpdate
without changing value of params in $location.search
?
In my application I use routeUpdate
to check if the $location.search
string has changed and navigate accordingly in my view.
Like so.
$scope.$on('$routeUpdate', function(next, current) {
var slide_key = $location.search().slide_key;
if (slide_key)
$scope.go_to_slide(slide_key);
});
Also keep in mind that I use reloadOnSearch
false to not reload the controller.
Usually I trigger this by changing the $location.search
and works fine
Everything works fine but there is a case where I want to trigger this behavior without changing the search parameters.
I tried to just change the search parameters to again the same value -> No luck.
If I change it to another value then the routeUpdate
fires and everything works ok.
So how can I manually trigger the routeUpdate
without changing value of params in $location.search
?
- 2 Could you put together a small jsfiddle for this please. It'll be easier to debug that way. Cheers – dcodesmith Commented Aug 2, 2013 at 10:28
- 1 I think I have idea on how to achieve this but I need some of your code (the controller maybe?) so I can see how my idea fits into your code. – dcodesmith Commented Aug 2, 2013 at 15:49
- @dcodesmith Just finished work, gonna go home and by tomorrow you ll havee the code. – Jimmy Kane Commented Aug 2, 2013 at 15:50
- Hey, still waiting :) – dcodesmith Commented Aug 3, 2013 at 7:39
- @dcodesmith, I think he meant his next work day.. I trimmed down the route example for my testing jsfiddle/BXAM4 – lossleader Commented Aug 4, 2013 at 13:26
1 Answer
Reset to default 6 +50I think you are right that you will have to manually interfere if you want to trigger a real $routeUpdate
event without a url change that affects $location.absUrl()
.
This example triggers the $routeUpdate event:
<a ng-click="$emit('$locationChangeSuccess','hiya')" href="">update route</a>
// or the precise broadcast would be:
// $rootScope.$broadcast('$locationChangeSuccess',$location.absUrl(), $location.absUrl())
But in your current code you do nothing with the parameters from $routeUpdate
, so you could also just broadcast a fake or alternate event for the $routeUpdate
.
Other alternatives that seem cleaner have reasons they can't work:
$route.reload()
always forces the real update path:
https://github./angular/angular.js/blob/master/src/ngRoute/route.js#L352 https://github./angular/angular.js/blob/master/src/ngRoute/route.js#L415
$location
is relying on parisons to $browser
's url, so you can't really get it to fire off normally without changing a meaningful part of the url:
https://github./angular/angular.js/blob/master/src/ng/location.js#L560
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745238718a4618045.html
评论列表(0条)