Angularjs With Bootstrap Tooltip
HTML
<script src="http://code.angularjs.org/1.0.1/angular-1.0.1.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<div ng-app="myApp">
<div ng-controller="MyCtrl">
<li ng-repeat="item in items" >
<a rel="tooltip" tooltip="item.tooltip">{{item.name}}</a>
<a href="#" tabindex="0" class="btn btn-lg btn-danger" data-toggle="popover" data-trigger="focus" title="Dismissible popover" popover="item">{{ item.name }} || {{ item.newProp }}</a>
</li>
</div>
</div>
JavaScript
var myApp = angular.module("myApp", []);
function MyCtrl($scope) {
$scope.items = [{ name: "item 01", tooltip: "This is item 01 tooltip!<hr>"},
{ name: "item 02", tooltip: "This is item 02 tooltip!"},
{ name: "item 03", tooltip: "This is item 03 tooltip!"},
{ name: "item 04", tooltip: "This is item 04 tooltip!"},
{ name: "item 05", tooltip: "This is item 05 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"});
}
}
})
myApp.directive('popover', function () {
return {
restrict:'A',
scope: { item: '=popover' },
link: function(scope, element, attrs)
{
scope.$watch('item', function(item) {
console.log(scope.item, item);
$(element).popover({
title: item.name,
content: item.tooltip
});
item.newProp = "done " + item.name;
});
}
}
})