Skip to content
This repository has been archived by the owner on Jan 17, 2022. It is now read-only.

Use ng-click inside intro injected html #28

Open
ahmedhawas opened this issue Sep 3, 2014 · 6 comments
Open

Use ng-click inside intro injected html #28

ahmedhawas opened this issue Sep 3, 2014 · 6 comments

Comments

@ahmedhawas
Copy link

Is there a way to use ng-click inside the injected html injected in the popup. I tried using ng-click to call a function in the controller but it doesnt seem to work. I am not sure if I am missing something. Thanks

@rodrigovallades
Copy link

Same question, anyone?

I imagine that the HTML has to be compiled before being injected, using $compile, but I can't make it work.

@ahmedhawas did you manage do solve this?

@DURK
Copy link

DURK commented Aug 18, 2015

Same here. Does anyone know a workaround? I'd like to use a directive inside the template of a step.

@DURK
Copy link

DURK commented Aug 18, 2015

@rodrigovallades @ahmedhawas I got it figured out using $compile!

First, define a callback on your ng-intro directive that's triggered when changing steps.

ng-intro-options="introOptions" ng-intro-onafterchange="onIntroAfterChange"

Second, configure the callback to compile the contents of the introjs-tooltip element. In my case, I've added a class 'compile' so I only compile the steps that need compiling.

$scope.onIntroAfterChange = function () {
    $timeout(function () {
        var el = angular.element('.introjs-tooltip');
        if (el.hasClass('compile')) {
            $compile(el.contents())($scope);
        }
    }, 500);
};

Note: even though it's triggered after a change, I needed a timeout to ensure the new step was rendered on the DOM.

Now you can add angular directives to the html of your steps, like an ng-click

{
    intro: '<button ng-click="onClick()">Click me</button>',
    tooltipClass : 'some-class compile'
}

Finally, the following method should be triggered!

$scope.onClick = function () {
    // great success!
}

@rodrigovallades
Copy link

Great, @DURK ! Thanks for the reply!

@pavlokitdev
Copy link

@DURK First of all - thanks for your solution.
I have one question: can we omit usage of $timeout for 500ms somehow?

@DURK
Copy link

DURK commented Apr 8, 2016

I haven't figured that out yet. I'll look into that when I get the chance.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants