-1

I want bootstrap tooltip with my mouse cursor. Is it possible to do that in angularjs. If not then what will be the alternative of this.

Derek 朕會功夫
  • 92,235
  • 44
  • 185
  • 247
Pranjal
  • 463
  • 1
  • 7
  • 20

1 Answers1

1

Yes, Let me explain it with example that how can you display tooltip with angularjs + Bootstrap.

Controller:

var myApp = angular.module("myApp", []);

function MyCtrl($scope) {
    $scope.items = [{ name: "item 01", tooltip: "This is item 01 tooltip!"},
                    { name: "item 02", tooltip: "This is item 02 tooltip!"}];
    console.log("MyCtrl");
}

myApp.directive('tooltip', function () {
    return {
        restrict:'A',
        link: function(scope, element, attrs)
        {
            $(element)
                .attr('title',scope.$eval(attrs.tooltip))
                .tooltip({placement: "right"});
        }
    }
})

HTML: Use tooltip at <a> html tag to display tooltip.

<div ng-app="myApp">
    <div ng-controller="MyCtrl">
        <li ng-repeat="item in items" >
            <a rel="tooltip" tooltip="item.tooltip">{{item.name}}</a>
        </li>
    </div>
</div>

And that's done. Please see live example.

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
AddWeb Solution Pvt Ltd
  • 21,025
  • 5
  • 26
  • 57
  • Sorry I think I does not explain it well. I need the tooltip move with the cursor, not fix with any anchor tag or other tag – Pranjal Jan 29 '16 at 08:44