-->

ng-click inside bs-tooltip not working

2019-09-17 09:01发布

问题:

I'm using angular-strap tooltip and inside I have link that should react to ng-click, but instead it's not responding.

.html

<span class="add-on input-group-addon" data-title="{{tooltips.date}}" bs-tooltip>
  <i class="glyphicon glyphicon-calendar fa fa-calendar"></i> Dates
</span>

.js

$scope.tooltips = {
  date: '<a class="btn btn-default" ng-click="select()">Select date</a>'
};

$scope.select = function() {
  //doing something and works fine outside tooltip
}

In app .config() there is html set to true.

angular.extend($tooltipProvider.defaults, {
  template: "static/lib/angular-strap/tooltip.tpl.html",
  trigger: 'click',
  html: true,
  placement: 'bottom-left'
});

回答1:

By using data-title along with html: true you are just passing some html, but it is not compiled by angular. If you want to use angular directives and data binding in your tooltip, use 'contentTemplate'; here is a working plunker: http://plnkr.co/LSl9gyHRKCMYoEGZZQei