The Angular bootstrap popover vanishes as soon as the mouse hovers over it

Currently, I am facing an issue with an angular bootstrap popover on some text. The problem arises when the user tries to click on a link inside the popover as it disappears. Additionally, when changing from one popover to another, the previous one does not close if configured to stay open on click instead of hover.

I have provided a example on jsfiddle for reference:

<div popover="{{careerAttribute.value}}"
     popover-append-to-body="true"
     popover-title="{{careerAttribute.title}}"
     popover-trigger="mouseenter"
     popover-placement="right"> HP
</div>

The desired behavior is for the popover to remain open when clicking on a link within it, and only one popover should be open at a time.

Answer №1

To achieve this, simply remove the popover-append-to-body attribute. By doing so, the popover will be appended to the current element instead. Instead of relying on the default popover-trigger, we can manually control the opening and closing of the popover from the parent element td. To do this, set the popover-trigger to none and use ng-mouseenter and ng-mouseleave on the parent to trigger the popover manually using popover-is-open. Keep track of open popovers by using an array. Additionally, ensure to properly sanitize the URL that will be displayed as HTML content in the popover.

Below is a functional example:

angular.module('myApp', ['ngAnimate', 'ngSanitize', 'ui.bootstrap'])
  .controller('myCtrl', ['$scope', '$sce', ($scope, $sce) => {
    $scope.isOpen = new Array(2).fill(false);
    $scope.careerAttribute = {
      'title': 'Here is The Title',
      'value': $sce.trustAsHtml('<a target="_blank" href="https://www.google.com">Google</a>')
    };
    
    $scope.open = (popoverId) => {
      $scope.isOpen[popoverId] = true;
    }
    
    $scope.close = (popoverId) => {
      $scope.isOpen[popoverId] = false;
    }
  }]);
[uib-popover-html] {
  margin: 25px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.7.5/angular-animate.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.7.5/angular-sanitize.js"></script>
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-2.5.0.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<div ng-app="myApp" ng-controller='myCtrl'>
  <table>
    <thead>
      <tr>
        <th>Name</th>
        <th>Address</th>
      </tr>
    </thead>
    <tr>
      <td ng-mouseenter="open(0)" ng-mouseleave="close(0)">
        <div uib-popover-html="careerAttribute.value" popover-title="{{careerAttribute.title}}" popover-is-open="isOpen[0]" popover-trigger="'none'" popover-placement="right">
          Hover for Popup
        </div>
      </td>
      <td>India</td>
    </tr>
    <tr>
      <td ng-mouseenter="open(1)" ng-mouseleave="close(1)">
        <div uib-popover-html="careerAttribute.value" popover-title="{{careerAttribute.title}}" popover-is-open="isOpen[1]" popover-trigger="'none'" popover-placement="right">
          Hover for Popup
        </div>
      </td>
      <td>India</td>
    </tr>
  </table>
</div>

Please Note: If clicking the link does not work within the code snippets on StackOverflow (while it works on other online code editors), you can right-click and open it in a new tab to verify functionality. This issue seems to stem from the snippets themselves, as even using the link directly in the HTML does not yield the expected result.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Clear Vuex state upon page refresh

In my mutation, I am updating the state as follows: try { const response = await axios.put('http://localhost:3000/api/mobile/v3/expense/vouchers/form_refresh', sendForm, { headers: { Accept: 'application/json', 'C ...

Can CSS be altered dynamically in Laravel blade?

Is there a way to dynamically change CSS? I am trying to set the class=sheet padding-top: 28mm; when the size of $anArray is less than 30. If the array has more than 30 elements then apply padding-top: 28 * 2 mm;. Finally, if the array exceeds 60, use pad ...

Dealing with undefined URL errors

My frontend log is crowded with these errors. Whenever I visit an undefined address, my terminal in VSCode displays the following error messages. The real issue is that I am unsure how to effectively manage errors arising from hitting an undefined URL. For ...

An error was encountered: "Uncaught SyntaxError: Unable to utilize import statement outside of a module in

I have come across the following code while learning React and trying to execute it. HTML <html> <head> <link href="index.css" rel="stylesheet"> </head> <body> <div id="r ...

Performing an HTTP GET request to an endpoint within a RESTful API

I am looking to integrate a feature in my web application that displays the list of online users on my website. To achieve this, I need to make an HTTP GET request to the URL which returns the user data in JSON format. The returned JSON data contains var ...

"The JavaScript code that functions perfectly in the browser console, but fails to execute when running in the actual

I'm encountering an issue with a simple piece of JavaScript code that seems to only work when executed in the browser console: <script> $(".hopscotch-close").click(function () { alert("Hi"); Cookies.set("tourState", "closed" ...

Sending data to mongodb using the fetch API and FormData method is a simple process that involves constructing

I have been trying to send data to mongoDB using the fetch API along with FormData, but encountering an error: POST https://xxxxxxxxxxxxxxxxxxxxxxxx/upload 500 (Internal Server Error) The form data in my EJS file appears as follows: <div id=" ...

The Vue component appears to be missing from the HTML code

I recently began learning Vue.js in school, and for my first assignment I need to print a h2 from a Vue component. However, I am having trouble getting it to work. Below is the code for the Vue component that I have created. var app = new Vue({ ...

Verification of email address is required, emails must be unique and not duplicated

I am working on validating email addresses to ensure they are not repeated. So far, I have successfully pushed them from the server into an array using regex for validation. What steps should I take next to compare and further validate these emails? ...

Chronological Overview (Highcharts)

Can you customize a timeline in Highcharts to resemble the image? https://i.sstatic.net/5Lipu.png I have a functional example of the timeline I desire, but the color coding and filtering aspects are challenging for me. I am attempting to apply a filter th ...

Executing an AngularJS function through CasperJS is a common task that can

I am facing a challenge with testing a directive within a controller. The unit tests I am trying to write involve executing this code, which is triggered not by a click event but rather by a socket.io emit. Instead of attempting to mock socket.io, I am exp ...

Guide on incorporating JSON information into an HTML table

Currently, I am retrieving data that needs to be added to an HTML table once it is received. I have attempted some methods, but I am unable to dynamically add the data after the page has loaded. I aim to accomplish this using either JavaScript or jQuery. ...

Tips for successfully passing multiple variables to the onload function within an Angular ng-include

I am facing a challenge in my Angular application where I need to pass two variables to a template. Here is what I have been trying: <div ng-include="'myTemplate.html'" onload="{obj: someObject, value: value}"></div> Unfortunately, ...

What is the best way to trigger the keyup event in that moment?

Currently, I am using regex to validate the name field. Each time a key is pressed, a validation function is triggered. If the input matches the regex pattern, I need to empty out that specific character from the input field. However, when previewing the p ...

AngularJS Sharepoint 2013 IE9 Sharepoint web part grouped error: The property 'replace' of undefined or null reference cannot be obtained

Encountering a browser error "Unable to get property 'replace' of undefined or null reference" while using AngularJS with IE9 and SharePoint 2013 on-premises, specifically when a SharePoint web part is grouped by any columns. Interestingly, IE10/ ...

Issues with Input Functionality in Angular and Internet Explorer 11

I am facing a critical problem with ng-model inputs in Internet Explorer (version 11 and earlier,) while they work perfectly fine in all other browsers. This issue started just last week, without any changes made to this part of our application or any prio ...

Looking for a way to efficiently add multiple value inputs to a JSON object using jQuery or JavaScript?

Here is the HTML input tag code I am working with: <form id="info"> <input id="A" name="A" type="hidden" nodetye="parent" value="A"> <input id="A1" name="A1" type="text" nodetype="child" value="a1val"> <input id="A2" name ...

Is it achievable to employ the object "angular" while still implementing the 'use strict' directive?

Whenever I use gulp-jshint, it requires me to include the 'use strict' directive in every file. This causes an issue with my global object emApp, defined in my app.js file as: var emApp = angular.module('emApp'); Interestingly, jshint ...

The addition of the woocommerce_add_to_cart action is causing issues with the website's native add to cart

After creating a node express API that listens for post requests from the woocommerce_add_to_cart webhook, I noticed that the payload it receives is not very useful. body:{ action: 'woocommerce_add_to_cart', arg:'098uoijo098920sa489983jk&ap ...

Unusual behavior observed within for loop; code within not running as expected

I will be presenting my code along with some images to illustrate the issue at hand. Something as simple as declaring a variable or using the log function results in the json being undefined. Upon entering text into the input field, the ajax call is trigg ...