How to update the URL without triggering a reload?

5,932 views
Skip to first unread message

Eric Jain

unread,
Mar 13, 2012, 3:13:58 PM3/13/12
to AngularJS
I'd like to be able to do e.g. $location.search('q', query) without
having the page reload. It looks like this can be accomplished by
setting reloadOnSearch to false for the route. But this breaks the
back button in the browser, as well as direct editing of the URL.
Suggestions?

Igor Minar

unread,
Mar 14, 2012, 2:21:28 PM3/14/12
to ang...@googlegroups.com
I think that you are missing a listener for the $routeUpdate event which would get notified whenever params change.

Once you disable the controller reloading, you are responsible for propagating the $location param changes to your model.

/i




--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.


Eric Jain

unread,
Mar 14, 2012, 4:57:18 PM3/14/12
to ang...@googlegroups.com
On Wed, Mar 14, 2012 at 11:21, Igor Minar <ig...@angularjs.org> wrote:
> I think that you are missing a listener for the $routeUpdate event which
> would get notified whenever params change.
>
> Once you disable the controller reloading, you are responsible for
> propagating the $location param changes to your model.

Thanks. Looks like this is the equivalent for 10.6.0?

this.$watch(function() { return $route.current.params; }, function() {
this.refresh();
});

Igor Minar

unread,
Mar 14, 2012, 5:19:34 PM3/14/12
to ang...@googlegroups.com
I think that it should be more like:

this.$on('$routeUpdate', function() {
  //refresh
});

Eric Jain

unread,
Mar 14, 2012, 5:25:20 PM3/14/12
to ang...@googlegroups.com
On Wed, Mar 14, 2012 at 14:19, Igor Minar <ig...@angularjs.org> wrote:
> I think that it should be more like:
>
> this.$on('$routeUpdate', function() {
>   //refresh
> });

You're sure that's supposed to work with 10.6.0?

Looks like the function never gets called...

Eric Jain

unread,
Mar 14, 2012, 8:41:02 PM3/14/12
to AngularJS
On Mar 14, 2:25 pm, Eric Jain <eric.j...@gmail.com> wrote:
> You're sure that's supposed to work with 10.6.0?
>
> Looks like the function never gets called...

For the record: I got $on('$routeUpdate') to work after upgrading to
1.0.0r1.
Reply all
Reply to author
Forward
0 new messages