Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Bootstrap Popover with Angular2

I am trying to get a Bootstrap 3 popover to display an Angular 2 interpolated template. Is this possible? Here is what I have so far:

    $('.ba-header--user-menu').popover({
      placement: 'bottom',
      toggle: 'popover',
      trigger: 'focus',
      html: true,
      content: '{{user.email}}'
    });

Which gives me this:

enter image description here

like image 529
Dylan Harness Avatar asked Mar 07 '16 02:03

Dylan Harness


People also ask

How does Bootstrap Popover work?

The Popover plugin is similar to tooltips; it is a pop-up box that appears when the user clicks on an element. The difference is that the popover can contain much more content. Tip: Plugins can be included individually (using Bootstrap's individual "popover. js" file), or all at once (using "bootstrap.

What is Popover in Angular?

Angular Popover with Bootstrap 4 & Material Design UI Popover is similar to tooltips; it is a pop-up box that appears when a user clicks or hovers on an element. Popovers whose both title and content are zero-length are never displayed. Examples. API.


2 Answers

JQuery and Angular don't play very well together. Install ng2-popover:

npm i ng2-popover

and use it like this:

<span popover="content to be shown in the popover">
    element on which this popover is applied.
</span>
like image 75
pleerock Avatar answered Sep 23 '22 19:09

pleerock


You can also try a library I published ng2-pop-over (not to be confused with ng2-popover mentioned above). It is compact and you'll have to add your styles but has what it takes to solve your problem without jQuery.

like image 25
Meir Avatar answered Sep 25 '22 19:09

Meir