0

I'm looking into the Angular Bootstrap UI tooltip, what i'd like to do is show the tool tip not on focus, or blur, but when I click a button. I know i can do this with a provider, but it's not clear how. I'd like to do this without Javascript or JQuery if possible, as i'm sure there's an Angular way :)

(function(){
    var app = angular.module("ngSignupPage", ['ui.bootstrap'])
        .controller("signUpController", function($scope) {      
            $scope.tooltipMessage = 'Hola mundo!';          
            $scope.showTooltip = function(){
                //  I'd like to show the tooltip with a custom message here
            };
        });
})();

<form name="signupForm" noValidate ng-submit="showTooltip()">
     <input 
        type="text" 
        tooltip="{{tooltipMessage}}" 
        tooltip-trigger="focus" /* Can i set this when 'showTooltip' is clicked? */
        tooltip-placement="bottom" />
    <button>Save</button>
</form>

1 Answer 1

1

UPDATE

Here's a better solution without Jquery using a directive to fire the customEvent.

On your app config you add the custom trigger:

.config(['$tooltipProvider', function($tooltipProvider){
  $tooltipProvider.setTriggers({'customEvent': 'customEvent'});
}]);

Html:

<div fire-custom-event>
  <span tooltip-html-unsafe="My <em>fancy</em> tooltip" tooltip-trigger="customEvent">Target for a tooltip</span>
  <button>Click me</button>
</div>

Directive:

angular.module('myApp').directive('fireCustomEvent', function () {
    return {
        restrict: "A",
        link: function (scope, element) {
            element.find('button').on('click', function () {
                element.find('span').trigger("customEvent");
            });
        }
    };
});

Check the demo here

FIRST ANSWER

On your app config you can add a custom trigger:

.config(['$tooltipProvider', function($tooltipProvider){
  $tooltipProvider.setTriggers({'customEvent': 'customEvent'});
}]);

And then in you controller you can fire the event. Unfortunately you need JQuery to do this:

angular.module('myApp').controller('myController', ['$scope','$timeout',
function($scope, $timeout) {
  $scope.fireCustomEvent = function() {
      $timeout(function() {
        $('#tooltipTarget').trigger('customEvent');
      }, 0);
    }
}]);

Check this demo here

Sign up to request clarification or add additional context in comments.

2 Comments

Perfect, that gets my head around the providers perfectly :) thanks!
Unfortunately the updated answer still relies on jquery

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.