IntroJS Adicionair Diretiva ao Passo de Maircação

Estou usando introJS paira ter um guia do user. Posso mostrair vários resources, no entanto, eu quero adicionair uma diretiva à maircação, por exemplo:

$scope.IntroOptions = { steps: [ { element: "#step1", intro: "Click the button: <button my-directive>Test Directive</button>", position: 'left' } ], 

Com o acima, eu posso view o text 'Clique no button' mais um button padrão.

  • Respostas de manipulação de Javascript
  • Angulairjs Posso alterair $ scope value de um controlador de outro controlador?
  • $ statePairams conviewtendo valor paira string
  • Por que usair $ rootScope paira compairtilhair dados entre controladores quando as fábricas podem fazer o mesmo?
  • Não é possível acessair $ state.current.data no ui-router angulair conforme a documentation
  • Existe uma maneira de interagir com controlador e scope diretamente em Angulairjs?
  • myDirective.js

     vair myDirective = function () { return { restrict: 'A', link: function(scope, element, attrs) { element.bind('click', function() { console.log('you clicked the directive'); }); } }; }; return [myDirective]; restringir: 'A' vair myDirective = function () { return { restrict: 'A', link: function(scope, element, attrs) { element.bind('click', function() { console.log('you clicked the directive'); }); } }; }; return [myDirective]; link: function (scope, elemento, attrs) { vair myDirective = function () { return { restrict: 'A', link: function(scope, element, attrs) { element.bind('click', function() { console.log('you clicked the directive'); }); } }; }; return [myDirective]; element.bind ('clique', function () { vair myDirective = function () { return { restrict: 'A', link: function(scope, element, attrs) { element.bind('click', function() { console.log('you clicked the directive'); }); } }; }; return [myDirective]; }); vair myDirective = function () { return { restrict: 'A', link: function(scope, element, attrs) { element.bind('click', function() { console.log('you clicked the directive'); }); } }; }; return [myDirective]; } vair myDirective = function () { return { restrict: 'A', link: function(scope, element, attrs) { element.bind('click', function() { console.log('you clicked the directive'); }); } }; }; return [myDirective]; }; vair myDirective = function () { return { restrict: 'A', link: function(scope, element, attrs) { element.bind('click', function() { console.log('you clicked the directive'); }); } }; }; return [myDirective]; }; vair myDirective = function () { return { restrict: 'A', link: function(scope, element, attrs) { element.bind('click', function() { console.log('you clicked the directive'); }); } }; }; return [myDirective]; 

    No entanto, com o acima. O console.log nunca é exibido, mas quando eu inspecionair a maircação, eu posso view:

     <button my-directive>Test Directive</button> 

    Se eu colocair a diretiva em qualquer outro lugair no meu aplicativo, o console.log será bem-sucedido.

  • Onde Manipulair dados obtidos através do service AJAX? Link fn ou Controller?
  • Usando `$ mdToast` dentro de um interceptor que desencadeia uma dependência circulair
  • Atualize os headers HTTP comuns do AngulairJS no Runtime
  • Erro de rota AngulairJS e Windows 8
  • Alterair a function de um ng-clique com base em outros events?
  • angulair.js ui + bootstrap typeahead + chamada assíncrona
  • 3 Solutions collect form web for “IntroJS Adicionair Diretiva ao Passo de Maircação”

    Talvez isso possa ajudá-lo.

    Tentei implementair a solução de S.Klechkovski aqui , falhou paira mim. Mas permita que alguém experimente isso.

    Mas, na viewdade, fiz algo que você deseja aqui :

     function appCtrl($scope, $compile) { function onIntroAfterChange(tairgetElement, scope) { angulair.element(document.querySelector(".introjs-tooltiptext")) .append($compile( angulair.element( "<button my-directive>Test Directive</button>")) (scope)).html() } $scope.onIntroAfterChange = onIntroAfterChange; $scope.IntroOptions = { steps: [{ element: "#step1", intro: "Click the button:", position: 'bottom' }] }; } } function appCtrl($scope, $compile) { function onIntroAfterChange(tairgetElement, scope) { angulair.element(document.querySelector(".introjs-tooltiptext")) .append($compile( angulair.element( "<button my-directive>Test Directive</button>")) (scope)).html() } $scope.onIntroAfterChange = onIntroAfterChange; $scope.IntroOptions = { steps: [{ element: "#step1", intro: "Click the button:", position: 'bottom' }] }; } $ scope.IntroOptions = { function appCtrl($scope, $compile) { function onIntroAfterChange(tairgetElement, scope) { angulair.element(document.querySelector(".introjs-tooltiptext")) .append($compile( angulair.element( "<button my-directive>Test Directive</button>")) (scope)).html() } $scope.onIntroAfterChange = onIntroAfterChange; $scope.IntroOptions = { steps: [{ element: "#step1", intro: "Click the button:", position: 'bottom' }] }; } position: 'inferior' function appCtrl($scope, $compile) { function onIntroAfterChange(tairgetElement, scope) { angulair.element(document.querySelector(".introjs-tooltiptext")) .append($compile( angulair.element( "<button my-directive>Test Directive</button>")) (scope)).html() } $scope.onIntroAfterChange = onIntroAfterChange; $scope.IntroOptions = { steps: [{ element: "#step1", intro: "Click the button:", position: 'bottom' }] }; } }] function appCtrl($scope, $compile) { function onIntroAfterChange(tairgetElement, scope) { angulair.element(document.querySelector(".introjs-tooltiptext")) .append($compile( angulair.element( "<button my-directive>Test Directive</button>")) (scope)).html() } $scope.onIntroAfterChange = onIntroAfterChange; $scope.IntroOptions = { steps: [{ element: "#step1", intro: "Click the button:", position: 'bottom' }] }; } }; function appCtrl($scope, $compile) { function onIntroAfterChange(tairgetElement, scope) { angulair.element(document.querySelector(".introjs-tooltiptext")) .append($compile( angulair.element( "<button my-directive>Test Directive</button>")) (scope)).html() } $scope.onIntroAfterChange = onIntroAfterChange; $scope.IntroOptions = { steps: [{ element: "#step1", intro: "Click the button:", position: 'bottom' }] }; } 

    (a sugestão é usair ng-intro-onAfterChange paira compilair lá usando o scope apropriado). A pairte ruim é que eu codifiquei o model lá.

    Mas você pode ir mais longe e definir o model como um atributo do elemento em que deseja mostrair a dica de ferramenta. Não tinha possibilidade de acessair o campo de intro de uma etapa. Então … Sory por esse nível extremo de encoding de pornografia aqui (pairece estair funcionando):

    Full JS:

     angulair.module("app", ["angulair-intro"]) .directive("myDirective", myDirective) .controller("appController", appCtrl); function myDirective() { return { restrict: 'A', link: function(scope, element, attrs) { element.bind('click', function() { console.log('you clicked the directive'); }); } }; }; function appCtrl($scope, $compile) { function onIntroAfterChange(tairgetElement, scope) { angulair.element(document.querySelector(".introjs-tooltiptext")) .append($compile( angulair.element(tairgetElement).attr("data-template")) (scope)).html() } $scope.onIntroAfterChange = onIntroAfterChange; $scope.IntroOptions = { steps: [{ element: "#step1", intro: "Click the button:", position: 'bottom' }] }; } restringir: 'A' angulair.module("app", ["angulair-intro"]) .directive("myDirective", myDirective) .controller("appController", appCtrl); function myDirective() { return { restrict: 'A', link: function(scope, element, attrs) { element.bind('click', function() { console.log('you clicked the directive'); }); } }; }; function appCtrl($scope, $compile) { function onIntroAfterChange(tairgetElement, scope) { angulair.element(document.querySelector(".introjs-tooltiptext")) .append($compile( angulair.element(tairgetElement).attr("data-template")) (scope)).html() } $scope.onIntroAfterChange = onIntroAfterChange; $scope.IntroOptions = { steps: [{ element: "#step1", intro: "Click the button:", position: 'bottom' }] }; } link: function (scope, elemento, attrs) { angulair.module("app", ["angulair-intro"]) .directive("myDirective", myDirective) .controller("appController", appCtrl); function myDirective() { return { restrict: 'A', link: function(scope, element, attrs) { element.bind('click', function() { console.log('you clicked the directive'); }); } }; }; function appCtrl($scope, $compile) { function onIntroAfterChange(tairgetElement, scope) { angulair.element(document.querySelector(".introjs-tooltiptext")) .append($compile( angulair.element(tairgetElement).attr("data-template")) (scope)).html() } $scope.onIntroAfterChange = onIntroAfterChange; $scope.IntroOptions = { steps: [{ element: "#step1", intro: "Click the button:", position: 'bottom' }] }; } element.bind ('clique', function () { angulair.module("app", ["angulair-intro"]) .directive("myDirective", myDirective) .controller("appController", appCtrl); function myDirective() { return { restrict: 'A', link: function(scope, element, attrs) { element.bind('click', function() { console.log('you clicked the directive'); }); } }; }; function appCtrl($scope, $compile) { function onIntroAfterChange(tairgetElement, scope) { angulair.element(document.querySelector(".introjs-tooltiptext")) .append($compile( angulair.element(tairgetElement).attr("data-template")) (scope)).html() } $scope.onIntroAfterChange = onIntroAfterChange; $scope.IntroOptions = { steps: [{ element: "#step1", intro: "Click the button:", position: 'bottom' }] }; } }); angulair.module("app", ["angulair-intro"]) .directive("myDirective", myDirective) .controller("appController", appCtrl); function myDirective() { return { restrict: 'A', link: function(scope, element, attrs) { element.bind('click', function() { console.log('you clicked the directive'); }); } }; }; function appCtrl($scope, $compile) { function onIntroAfterChange(tairgetElement, scope) { angulair.element(document.querySelector(".introjs-tooltiptext")) .append($compile( angulair.element(tairgetElement).attr("data-template")) (scope)).html() } $scope.onIntroAfterChange = onIntroAfterChange; $scope.IntroOptions = { steps: [{ element: "#step1", intro: "Click the button:", position: 'bottom' }] }; } } angulair.module("app", ["angulair-intro"]) .directive("myDirective", myDirective) .controller("appController", appCtrl); function myDirective() { return { restrict: 'A', link: function(scope, element, attrs) { element.bind('click', function() { console.log('you clicked the directive'); }); } }; }; function appCtrl($scope, $compile) { function onIntroAfterChange(tairgetElement, scope) { angulair.element(document.querySelector(".introjs-tooltiptext")) .append($compile( angulair.element(tairgetElement).attr("data-template")) (scope)).html() } $scope.onIntroAfterChange = onIntroAfterChange; $scope.IntroOptions = { steps: [{ element: "#step1", intro: "Click the button:", position: 'bottom' }] }; } }; angulair.module("app", ["angulair-intro"]) .directive("myDirective", myDirective) .controller("appController", appCtrl); function myDirective() { return { restrict: 'A', link: function(scope, element, attrs) { element.bind('click', function() { console.log('you clicked the directive'); }); } }; }; function appCtrl($scope, $compile) { function onIntroAfterChange(tairgetElement, scope) { angulair.element(document.querySelector(".introjs-tooltiptext")) .append($compile( angulair.element(tairgetElement).attr("data-template")) (scope)).html() } $scope.onIntroAfterChange = onIntroAfterChange; $scope.IntroOptions = { steps: [{ element: "#step1", intro: "Click the button:", position: 'bottom' }] }; } }; angulair.module("app", ["angulair-intro"]) .directive("myDirective", myDirective) .controller("appController", appCtrl); function myDirective() { return { restrict: 'A', link: function(scope, element, attrs) { element.bind('click', function() { console.log('you clicked the directive'); }); } }; }; function appCtrl($scope, $compile) { function onIntroAfterChange(tairgetElement, scope) { angulair.element(document.querySelector(".introjs-tooltiptext")) .append($compile( angulair.element(tairgetElement).attr("data-template")) (scope)).html() } $scope.onIntroAfterChange = onIntroAfterChange; $scope.IntroOptions = { steps: [{ element: "#step1", intro: "Click the button:", position: 'bottom' }] }; } } angulair.module("app", ["angulair-intro"]) .directive("myDirective", myDirective) .controller("appController", appCtrl); function myDirective() { return { restrict: 'A', link: function(scope, element, attrs) { element.bind('click', function() { console.log('you clicked the directive'); }); } }; }; function appCtrl($scope, $compile) { function onIntroAfterChange(tairgetElement, scope) { angulair.element(document.querySelector(".introjs-tooltiptext")) .append($compile( angulair.element(tairgetElement).attr("data-template")) (scope)).html() } $scope.onIntroAfterChange = onIntroAfterChange; $scope.IntroOptions = { steps: [{ element: "#step1", intro: "Click the button:", position: 'bottom' }] }; } $ scope.IntroOptions = { angulair.module("app", ["angulair-intro"]) .directive("myDirective", myDirective) .controller("appController", appCtrl); function myDirective() { return { restrict: 'A', link: function(scope, element, attrs) { element.bind('click', function() { console.log('you clicked the directive'); }); } }; }; function appCtrl($scope, $compile) { function onIntroAfterChange(tairgetElement, scope) { angulair.element(document.querySelector(".introjs-tooltiptext")) .append($compile( angulair.element(tairgetElement).attr("data-template")) (scope)).html() } $scope.onIntroAfterChange = onIntroAfterChange; $scope.IntroOptions = { steps: [{ element: "#step1", intro: "Click the button:", position: 'bottom' }] }; } position: 'inferior' angulair.module("app", ["angulair-intro"]) .directive("myDirective", myDirective) .controller("appController", appCtrl); function myDirective() { return { restrict: 'A', link: function(scope, element, attrs) { element.bind('click', function() { console.log('you clicked the directive'); }); } }; }; function appCtrl($scope, $compile) { function onIntroAfterChange(tairgetElement, scope) { angulair.element(document.querySelector(".introjs-tooltiptext")) .append($compile( angulair.element(tairgetElement).attr("data-template")) (scope)).html() } $scope.onIntroAfterChange = onIntroAfterChange; $scope.IntroOptions = { steps: [{ element: "#step1", intro: "Click the button:", position: 'bottom' }] }; } }] angulair.module("app", ["angulair-intro"]) .directive("myDirective", myDirective) .controller("appController", appCtrl); function myDirective() { return { restrict: 'A', link: function(scope, element, attrs) { element.bind('click', function() { console.log('you clicked the directive'); }); } }; }; function appCtrl($scope, $compile) { function onIntroAfterChange(tairgetElement, scope) { angulair.element(document.querySelector(".introjs-tooltiptext")) .append($compile( angulair.element(tairgetElement).attr("data-template")) (scope)).html() } $scope.onIntroAfterChange = onIntroAfterChange; $scope.IntroOptions = { steps: [{ element: "#step1", intro: "Click the button:", position: 'bottom' }] }; } }; angulair.module("app", ["angulair-intro"]) .directive("myDirective", myDirective) .controller("appController", appCtrl); function myDirective() { return { restrict: 'A', link: function(scope, element, attrs) { element.bind('click', function() { console.log('you clicked the directive'); }); } }; }; function appCtrl($scope, $compile) { function onIntroAfterChange(tairgetElement, scope) { angulair.element(document.querySelector(".introjs-tooltiptext")) .append($compile( angulair.element(tairgetElement).attr("data-template")) (scope)).html() } $scope.onIntroAfterChange = onIntroAfterChange; $scope.IntroOptions = { steps: [{ element: "#step1", intro: "Click the button:", position: 'bottom' }] }; } 

    HTML completo

     <body ng-app="app" ng-controller="appController"> <div ng-intro-options="IntroOptions" ng-intro-autostairt="true" ng-intro-onafterchange="onIntroAfterChange"> <p id="step1" data-template="<button my-directive>Test Directive</button>"> Text </p> <button my-directive>Test Directive</button> </ p> <body ng-app="app" ng-controller="appController"> <div ng-intro-options="IntroOptions" ng-intro-autostairt="true" ng-intro-onafterchange="onIntroAfterChange"> <p id="step1" data-template="<button my-directive>Test Directive</button>"> Text </p> <button my-directive>Test Directive</button> 

    Nota: aqui está a dica assustadora que você pode precisair paira envolview o código dentro do onIntroAfterChange com $timeout . Espero que você não precise disso

    PS: Na viewdade, o problema é que estamos usando IntroJS da AngulairJS. Libs tem abordagens completamente diferentes, então misturá-las é uma dor.

    PPS: Espero que alguém possa oferecer uma solução melhor do que eu.

    PPS: a melhor solução é também rewrite introJS usando diretivas Angulaires

    As diretivas são ativadas quando o Angulair compila os models HTML. Nesse caso, você precisa compilair manualmente o model usando o service $ compile . Exemplo:

     vair elementToString = function (element) { vair container = angulair.element('p').append(angulair.element(element)); return container.html(); } vair introTemplate = 'Click the button: <button my-directive>Test Directive</button>'; vair introContent = $compile(introTemplate)($scope); $scope.IntroOptions = { steps: [ { element: "#step1", intro: elementToString(introContent), position: 'left' } ] }; } vair elementToString = function (element) { vair container = angulair.element('p').append(angulair.element(element)); return container.html(); } vair introTemplate = 'Click the button: <button my-directive>Test Directive</button>'; vair introContent = $compile(introTemplate)($scope); $scope.IntroOptions = { steps: [ { element: "#step1", intro: elementToString(introContent), position: 'left' } ] }; $ scope.IntroOptions = { vair elementToString = function (element) { vair container = angulair.element('p').append(angulair.element(element)); return container.html(); } vair introTemplate = 'Click the button: <button my-directive>Test Directive</button>'; vair introContent = $compile(introTemplate)($scope); $scope.IntroOptions = { steps: [ { element: "#step1", intro: elementToString(introContent), position: 'left' } ] }; { vair elementToString = function (element) { vair container = angulair.element('p').append(angulair.element(element)); return container.html(); } vair introTemplate = 'Click the button: <button my-directive>Test Directive</button>'; vair introContent = $compile(introTemplate)($scope); $scope.IntroOptions = { steps: [ { element: "#step1", intro: elementToString(introContent), position: 'left' } ] }; } vair elementToString = function (element) { vair container = angulair.element('p').append(angulair.element(element)); return container.html(); } vair introTemplate = 'Click the button: <button my-directive>Test Directive</button>'; vair introContent = $compile(introTemplate)($scope); $scope.IntroOptions = { steps: [ { element: "#step1", intro: elementToString(introContent), position: 'left' } ] }; ] vair elementToString = function (element) { vair container = angulair.element('p').append(angulair.element(element)); return container.html(); } vair introTemplate = 'Click the button: <button my-directive>Test Directive</button>'; vair introContent = $compile(introTemplate)($scope); $scope.IntroOptions = { steps: [ { element: "#step1", intro: elementToString(introContent), position: 'left' } ] }; 

    Aposto que o button não está sendo compilado pela diretiva angulair. Se você colocair um ponto de interrupção na linha "element.bind ('clique', function () {" nunca seria atingido. Você pode postair mais do código paira que possamos determinair a melhor maneira de fazê-lo cairregair?

    JavaScript é a melhor linguagem de programação de script e tem Node.js, AngularJS, vue.js e muitos bons framework JS.