angular-intro.js icon indicating copy to clipboard operation
angular-intro.js copied to clipboard

It seems not working well when content is inside a template

Open gudh opened this issue 11 years ago • 7 comments

It seems not working well when content is inside a template

That is, content is pull in using ngView, ngInclude directive. And intro.js text just show in the middle of the page instead of pointing to the element.

gudh avatar May 14 '14 11:05 gudh

Having the same issue loading a template in with a directive. The document.querySelector() call gets back null as the template has not yet loaded in. Calling document.querySelector() in the JS console will get back the element I want so I assume this has to do with the timing of getting the element.

houli avatar Jul 14 '14 15:07 houli

Same issue using a directive with a template. Any ideas?

deloschang avatar Sep 28 '14 05:09 deloschang

bump? please?

manwaring avatar Apr 18 '15 02:04 manwaring

Actually just found a (somewhat unsatisfactory) resolution to this, hopefully it can help someone else. It seems to be related to issue #48. The code I put in sets a timeout before calling the init function, and inside the timeout (before the init call) I load the steps like so:

setTimeout(function(){
      $scope.introOptions.steps = [
        {
          element : document.querySelector('#1'),
          intro : 'blah blah',
          position : 'left'
        },
        {
          element : document.querySelector('#2'),
          intro : 'blah blah',
          position : 'left'
        },
        {
          element : document.querySelector('#3'),
          intro : 'blah blah',
          position : 'left'
        },
        {
            element : document.querySelector('#4'),
            intro : 'blah blah',
            position : 'left'
          },];
      $scope.introOptions.start();
    }, 1000);

manwaring avatar Apr 18 '15 03:04 manwaring

I was able to solve this issue by putting the directive in the parent index.html file and using the CallMe() callback

directive

<div ng-controller="IntroController">
    <div ng-intro-options="IntroOptions"  ng-intro-method="CallMe"
         ng-intro-autostart="ShouldAutoStart"
         ng-intro-autorefresh="true"></div>
    <div ng-view id='introStep-2'></div>
</div>

end of controller

$scope.ShouldAutoStart = false;
$timeout(function(){$scope.CallMe()},1000);

CrouseMatthew avatar Apr 21 '15 00:04 CrouseMatthew

A solution that worked for us, but will need to be tweaked for others (YMMV). If you need to put a tooltip on a particular selector say "#selector", then you need to change/modify the introOptions when that element becomes available, so what you can do is:

$scope.$watch(function() {
    return $("#selector").length;
}, function() {
    $scope.introOptions.steps = [
    {
        element: document.querySelector("#selector"),
        intro: '
    }
});

Obviously you rarely ever need it over a single element, so you will need to use a $watchGroup and do it accordingly, or in the watch expression, you can add a boolean expression over the presence of elements:

$scope.$watch(function() {
   return ($("#selector1").length == 1) && $("#selector2").length == 2);
}, function() { ... });

Do note that, none of this will work if autostart is set to true. You will need to trigger the CallMe function (or whatever), from the aggregated watch function.

RohanPrabhuNomadly avatar Apr 22 '15 05:04 RohanPrabhuNomadly

Thank you @RohanPrabhuNomadly! Your answer just solved all my problems with loading the steps on the right timing. 🙏

amiltonpaglia avatar Jul 28 '16 14:07 amiltonpaglia