Returning to the same location (anchor) in a list view

788 views
Skip to first unread message

Sean Gilligan

unread,
Jan 6, 2012, 12:54:06 AM1/6/12
to ang...@googlegroups.com
Hi Again,

I have an app that loads a list view of up to 100 user profiles as the
default view. Clicking on one of the profiles navigates to the detail
view for that profile.

The default/list view is: /query#!/list
The detail view is: /query#!/<profile-id>/main

I have added an anchor tag to each list item in the list view that is
<prefix>+<profile-id>
Let's say the prefix is 'pid'

I am using angular 0.10.5 and the $route service.

If the user navigates to a profile detail view from the 80th item (let's
say profile id 1001) in the list and then returns to this list (by
either clicking a "Return" button in the UI or by using the browser back
button) I want the list to scroll to the 'pid1001' anchor inside the
list view (route)

I've unsuccessfully tried 2 approaches and I've also noticed some
unreleased code in the trunk that looks like it might address this issue?

How can I implement this this week? If I wait for 0.10.6 will this be
easier?

Thanks,

Sean

ProLoser

unread,
Jan 6, 2012, 2:30:25 PM1/6/12
to ang...@googlegroups.com
May seem like a hack but check out this fiddle http://jsfiddle.net/ProLoser/MSgZZ/

Occurred to me while reading your question. I realize however that this is probably an invalid ID, but it might be a viable hack if all else fails.

Sean Gilligan

unread,
Jan 6, 2012, 5:45:46 PM1/6/12
to ang...@googlegroups.com, ProLoser
On 1/6/12 11:30 AM, ProLoser wrote:
> May seem like a hack but check out this
> fiddle http://jsfiddle.net/ProLoser/MSgZZ/

I'm not sure I understand how your hack would apply to my situation.
I'm using the $route service and the ng:view and ng:include tags. I
want $route to change the view and then scroll to an element within the
new view.

-- Sean

Sean Gilligan

unread,
Jan 6, 2012, 6:00:00 PM1/6/12
to ang...@googlegroups.com
On 1/5/12 9:54 PM, Sean Gilligan wrote:
> The default/list view is: /query#!/list
> The detail view is: /query#!/<profile-id>/main
>
> If the user navigates to a profile detail view from the 80th item
> (let's say profile id 1001) in the list and then returns to this list
> (by either clicking a "Return" button in the UI or by using the
> browser back button) I want the list to scroll to the 'pid1001' anchor
> inside the list view (route)

I see in the trunk code there is an $autoScroll service that looks at
first glance like it might do what I need. Should I try to build and
use this, should I wait for the next release (especially if it is coming
soon), or is there something else I can do?

Vojta Jina

unread,
Jan 6, 2012, 6:32:08 PM1/6/12
to ang...@googlegroups.com
Hi Sean,

I guess you want ng:view to scroll to anchor after loading.
When you press back button, url changes, it matches different route, so ng:view change it's content... after loading the content, you wanna scroll to given position (in your case anchor #pid-1001), right ?

This feature has already been implemented for both ng:view and ng:include, see https://github.com/vojtajina/angular.js/blob/master/src/service/autoScroll.js

Guess what, it's in the master, but not released yet...

V.

Sean Gilligan

unread,
Jan 6, 2012, 9:12:20 PM1/6/12
to ang...@googlegroups.com, Vojta Jina
On 1/6/12 3:32 PM, Vojta Jina wrote:
> When you press back button, url changes, it matches different route,
> so ng:view change it's content... after loading the content, you wanna
> scroll to given position (in your case anchor #pid-1001), right ?
> I guess you want ng:view to scroll to anchor after loading.


Exactly.


> This feature has already been implemented for both ng:view and
> ng:include,
> see https://github.com/vojtajina/angular.js/blob/master/src/service/autoScroll.js


I briefly looked at the code and I thought it does what I'm looking for. :)


> Guess what, it's in the master, but not released yet...


So, what are my options?

I can think of two:
a) Make my own build - how easy is that? - can I get a stable
version that way?
b) Wait for 0.10.6 - is it coming soon? - any estimate of a release
date?

Any other ideas?

-- Sean

Vojta Jina

unread,
Jan 6, 2012, 11:05:47 PM1/6/12
to ang...@googlegroups.com, Vojta Jina
I would recommend you to wait for 0.10.6 release. We are staying late to make it tonight, but it will probably not happen, so hopefully on Monday...

You can get current build from our CI server, this is current master: http://ci.angularjs.org/job/angular.js-angular-master/170/artifact/build/pkg/0.10.6-08029c7b/

V.

eelkeh...@gmail.com

unread,
Sep 30, 2012, 7:25:40 PM9/30/12
to ang...@googlegroups.com, Vojta Jina
Having the same problem, I'm not sure the $autoScroll service is in the source anymore, is there any other way to fix this?
Reply all
Reply to author
Forward
0 new messages