Popover + Angular + Bootstrap 4.3 Failure

Viewed 3058

I am trying to use the sample code popover element from the getbootstrap site.

Environment: Angular 8.0.0 JQuery 3.4.1 Popper.js 1.15.0 Bootstrap 4.3.1 ToolTip 1.6.1

angular.json I have loaded the scripts

"scripts": [
  "node_modules/jquery/dist/jquery.min.js",
  "node_modules/popper.js/dist/popper.min.js",
  "node_modules/tooltip/dist/Tooltip.js",
  "node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"]

},

style.css

@import "~bootstrap/dist/css/bootstrap.css";

index.html

<script>
  $(function () {
    $('[data-toggle="popover"]').popover()
  })
</script>

<button type="button" class="btn btn-lg btn-danger" data-toggle="popover" title="Popover title" data-content="And here's some amazing content. It's very engaging. Right?">Click to toggle popover</button>
<button type="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="top" title="Tooltip on top">
  Tooltip on top
</button>
<script>
  $(function () {
    $('[data-toggle="popover"]').popover()
  })
</script>

Bootstrap styling seems to work fine, but sample tooltip and popovers do not.

Even when I load the with the CDN method, I cant seem to get these to work.

  1. There are no compile errors and the scripts[] from angular.json seems to be working

  2. When I run a jquery test in index.html, I'm told it's not running. Clearly I dont understand what angular.json scripts[] directive is providing. Is there something else I should be adding to make the libraries available?

  3. When I load via CDN, I get the following error in the console:

Uncaught Error: TOOLTIP: Option "sanitizeFn" provided type "window" but expected type "(null|function)"

2 Answers

I had the same issue with tooltip. A possible workaround is to define a sanitize function and set sanitize to false to avoid this function to be called.

My code before

jQuery(this.elementRef.nativeElement).tooltip({placement: place, trigger: 'hover'});

The working function with Angular 8

jQuery(this.elementRef.nativeElement).tooltip({
   placement: place, trigger: 'hover', sanitize: false, sanitizeFn: content => content
});
Related