DaftMonk / angular-tour

AngularJS directive for giving an interactive tour of your website.
http://daftmonk.github.io/angular-tour/
MIT License
608 stars 137 forks source link

Unable to dynamically add (virtual) steps with ng-repeat #62

Open pascal08 opened 8 years ago

pascal08 commented 8 years ago

TourSteps (demoTour.json)

[
    {
        "textKey": "test1",
        "placement": "bottom",
        "element": "#element1"
    },
    {
        "textKey": "test2",
        "placement": "bottom",
        "element": "#element2"
    },
    {
        "textKey": "test3",
        "placement": "bottom",
        "element": "#element3"
    }
]

Directive (demoTourDirective.js)

[...]
        restrict: 'A',
        scope: true,
        template: $templateCache.get('demoTourDirective.html'),

        link: function (scope) {

            scope.currentStep = 0;

            scope.tourSteps = [];

           // retrieves demoTour.json
            DemoTourService.get().then(function (tourSteps) {
                scope.tourSteps = tourSteps;
            });
        }
[...]

Template (demoTourDirective.html)

[...]
<tour step="currentStep" post-step="stepComplete()">
    <virtual-step data-ng-repeat="step in tourSteps"
        data-ng-attr-tourtip="{{ step.textKey | translate }}"
        data-ng-attr-tourtip-step="{{ $index }}"
        data-ng-attr-tourtip-placement="{{ step.placement || undefined }}"
        data-ng-attr-tourtip-element="{{ step.element || undefined }}">
    </virtual-step>
</tour>
[...]

I've tried to:

It really seems like angular-tour is consuming the template before the ng-repeat loops is compiled by angular. Though, when I place a hardcoded step in front of the ng-repeat loop it works.

Some other possible solutions have crossed my mind, but most of them are obscure and really not worth implementing since I would be better of hardcoding my steps instead.

mattifh commented 7 years ago

Have you ever found a way to make your ng-repeat to work? I am facing the same issue.

mattifh commented 7 years ago

@DaftMonk @pascal08 any input you can provide is highly appreciated. Let me know if this is not even possible.

pascal08 commented 7 years ago

It is possible by adding the steps before the loop, as I mentioned. I haven't found another way to get this to work sadly.