angular-scroll icon indicating copy to clipboard operation
angular-scroll copied to clipboard

Multiple du-scrollspy directives not working

Open MrBlenny opened this issue 9 years ago • 7 comments

It looks like you cannot have multiple du-scroll spy directives active at the same time.

Image a TOC as follows. Only the first instance of ng-repeat will work with scrollspy - the other 2 will do nothing.

    <div ng-init="sections = [1,2,3,4]"></div>
    <div ng-repeat="section in sections" du-scrollspy="{{section}}">{{section}}</div>
    <div ng-repeat="section in sections" du-scrollspy="{{section}}">{{section}}</div>
    <div ng-repeat="section in sections" du-scrollspy="{{section}}">{{section}}</div>

MrBlenny avatar Feb 26 '16 00:02 MrBlenny

This also caused problem on my project... having to abandon this library because of this issue.

masyl avatar Apr 03 '16 17:04 masyl

Did you guys tried to add an offset?

tenshiAMD avatar Apr 08 '16 08:04 tenshiAMD

Works fine for me. You may need a {{du-spy-context}} though:

<ul du-spy-context
      du-scroll-container="questionnaireList">

    <li ng-repeat="section in sections">
        <div du-scrollspy="{{section}}"></div>
    </li>

</ul>

RIAstar avatar Apr 29 '16 07:04 RIAstar

Perhaps one other difference, I'm not passing the target ID to scrollspy, but to smooth-scroll:

<div du-scrollspy
      du-smooth-scroll="{{section}}">
</div>

RIAstar avatar Apr 29 '16 07:04 RIAstar

You also only have one instance AFAICS. You will notice mine has 3 ng-repeats. It works with one, just not more than one.

MrBlenny avatar May 01 '16 02:05 MrBlenny

In fact I have multiple ng-repeats because they are repeated themselves. Even more: I have nested ng-repeats that each have scrollspys.

I didn't want to throw the whole block of code at you, but since it might help, here it is (I'll try and cut the irrelevant parts):

<ul du-spy-context
      du-scroll-container="questionnaireList">

    <li>
        <a href="#{{::$ctrl.target}}"
             du-scrollspy
             du-smooth-scroll></a>
    </li>

    <li ng-repeat="group in $ctrl.data.groups">

        <a href="#{{::$ctrl.group.target}}"
             du-scrollspy
             du-smooth-scroll></a>

        <ul du-spy-context="questionnaire"
              du-scroll-container="questionnaireList">
            <li ng-repeat="product in ::$ctrl.group.questionnaires">

                <div du-scrollspy
                        du-smooth-scroll="questionnaire_{{::$ctrl.product.id}}">
                </div>

            </li>
        </ul>

    </li>

    <li>
        <a href="#assessmentCheckout"
             du-scrollspy
             du-smooth-scroll></a>
    </li>

</ul>

If you wonder about du-spy-context="questionnaire" that's some custom functionality that I added in a fork for a specific use case, but it will work without it.

RIAstar avatar May 10 '16 13:05 RIAstar

I seem to be having the same issue. Is there any workaround?

anselanza avatar Oct 14 '16 14:10 anselanza