The ng-click event is unresponsive within the content of a bootstrap popover

I need to display a clickable table inside a popover, and trigger a function when a row is clicked. My HTML code appears as follows:

<a popover  id="showDays"
    type="button"
    class="btn btn-success btn-xs pull-left"
    data-toggle="popover"
    data-placement="right"
    data-html="true"
    title="Popover title"
    data-content=
    '<table class="table table-condensed">
       <tbody>
         <tr ng-repeat="d in days" ng-click="show(111)">
           <td ng-bind="d"></td>
           <td ng-bind="x"></td>
         </tr>
       </tbody>
     </table>'>
      <i class="fa fa-clock-o fa-lg">Click me</i>
 </a>

Here's my script.js: var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
  $scope.days = [
  'Sunday',
  'Monday',
  ];
  $scope.show = function(x) {
    console.log("show called with " + x);
    $scope.x = x;
  }
}).directive('popover', function($compile, $timeout){
  return {
    restrict: 'A',
    link:function(scope, el, attrs){
      var content = attrs.content;
      var elm = angular.element('<div />');
      elm.append(attrs.content);
      $compile(elm)(scope);
      $timeout(function() {
        el.removeAttr('popover').attr('data-content',elm.html());
        el.popover();
       });
    }
  }
});

Check out the demo here

The original code was taken from this forum thread, where the solution seems to be working fine. However, I'm facing an issue where my show function does not get executed. Any thoughts on why this might be happening?

Answer №1

After thorough investigation, I have identified the issue. It appears that the directive failed to properly bind the function show with scope, while it succeeded with days. I conducted several experiments and found that altering the way the link function is written allowed ng-click to function correctly, but caused ng-repeat to fail in binding days.

To address this problem, the updated DEMO now utilizes templateUrl instead of the data-content attribute.

<script type="text/ng-template" id="popover-content">
     <table class="table table-condensed">
       <tbody>
         <tr ng-repeat="d in days" role="button" ng-click="show(111)">
           <td ng-bind="d"></td>
           <td ng-bind="x"></td>
         </tr>
       </tbody>
     </table>
    </script>

With these adjustments, both ng-repeat and ng-click functions now operate smoothly for me.

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

incorporate a new component in real-time

I need help with dynamically adding components to my container in AngularJS. I have a componentA that functions as a container, and I want to add multiple instances of componentB when a button is pressed. Currently, I can successfully add a single instanc ...

Failure to fetch data through Axios Post method with a Parameter Object

I've encountered an issue with Axios while attempting to make a post request with a parameters object to a Laravel route. If I use query parameters like ?username=user, the post request works successfully. However, when I use an object, it fails: Be ...

Extracting the route path without parameters in Vue Router interceptors - is it possible?

I am trying to extract the base path of a route in my Vue Router interceptor without including its parameters. router.beforeEach((to, from, next) => { console.log(to); }) For example, if the route is /profile/abc/def where abc and def are dynamic ...

Collaboration of Bootstrap components

I am facing an issue with two divs that are supposed to be displayed side by side in a normal browser. However, when the browser window is resized, the first div loses its height and the second div overlaps into it. I attempted to set the body's min h ...

React.js: Issue with triggering handleSubmit or onClick when rendered on the server side is not being recognized

Encountering an issue with server-side rendering and triggering a handleSubmit event. Here is the code snippet: index.js: module.exports = require('./app/server'); app/server/index.js: 'use strict'; var env = process.env.NODE_ENV | ...

Upon upgrading to webpack 5.x, I encountered the error message `Error: getaddrinfo ENOTFOUND localhost:8081` when trying to run `npm run serve`. What could be causing

Recently, I was tasked with upgrading a Vue project from webpack 4.x to webpack 5.x. Prior to the upgrade, my vue.config.js file looked like this: devServer: { port: 8081, public: process.env.PUBLIC_ADDRESS, }, The variable PUBLIC_ADDRESS was defined ...

Utilizing lodash to Filter Arrays Within Arrays

Let's take a look at the JSON structure provided below. comapany : ABC Emp Info:[ { empName: D, empID:4 salary[ { year: 2017, ...

Trouble with Swiper carousel loading new slides

Currently, I am working on a project using Cordova and jQuery. I have implemented the Swiper library by idangero for handling slides. The problem arises when I add new slides and try to display them. Here is the relevant jQuery code snippet: if(row.pict ...

Updating a string in JavaScript by dynamically adding values from a JSON object

In my current function, I am making a request to fetch data and storing it as an object (OBJ). Afterwards, I make another request to get a new URL that requires me to update the URL with values from the stored data. The information saved in the object is ...

Experiencing an issue with excess right padding when utilizing Bootstrap 4.5 cards

I am attempting to implement this specific bootstrap 4.5 card layout in my react application, but I am encountering the following two problems: All three cards in the deck have an additional right padding of 44px. The card header is lacking a complete bor ...

Center the panel on the page and decrease its width using Bootstrap

I recently incorporated a Bootstrap panel above a search results table - my first experience working with Panels. This panel contains a form with a select menu, allowing users to filter the list of search results based on their selections. Currently, the ...

The transition property in CSS and JavaScript does not seem to be functioning properly in Firefox

Recently, I integrated a Slide in menu script on my website using a Slide in menu script. After following all the instructions provided, the menu started working flawlessly on Chrome and Safari browsers. However, my main goal was to make it function on Fir ...

Exploring the implementation of AES encryption and decryption functionality between Java and JavaScript

Currently, I am working on implementing an AES/CBC/PKCS5Padding algorithm. Initially, I used CryptoJS in JavaScript and was amazed by how smoothly encryption and decryption worked within seconds. Despite my efforts, I struggled to find a compatible solutio ...

Stretching a row in Wordpress Visual Composer and setting the direction to Right-to-Left

Whenever I attempt to expand a row using the row settings in Visual Composer, the row stretches but the alignment of the row becomes completely off. This issue only occurs when the body direction is set to direction:rtl in the CSS. You can view the websit ...

JavaScript watermark with alternating/dual mode

In the following code snippet, I have implemented a function to make window.status switch between displaying "a" and "b." function alternateViaIntrvl() { setInterval('alterStatus()', 500); } var altrCounter = 0; function alerted() { var ...

Eliminate any properties with values that exceed the specified number in size

:) I'm trying to create a function that removes properties with values greater than a specified number. I've searched through multiple resources like this question on how to remove properties from a JavaScript object and this one on removing pro ...

Occasionally encounter errors while fetching data with the Twitter API

Occasionally, I encounter a problem with the code below. Sometimes it works fine, but other times it throws error 420 with a vague JSON parse error message. Any suggestions on what might be causing this issue? The error message is as follows: Error gett ...

Issues arising with carousel pager in Cycle2 slideshow not functional

Our unique pager is designed with the "Advanced Custom Template" on a dynamic carousel slideshow. Everything seems to be running smoothly until I interact with the pager - then things start acting strangely. The active slide doesn't change position a ...

Troubleshooting the issue of "Mismatched transaction number*" in MongoDB and Node.js

While trying to add data, I encountered an issue with modifying two schemas using ACID transactions in MongoDB with Node.js. Upon running the program, an error was displayed: (node:171072) UnhandledPromiseRejectionWarning: MongoError: Given transaction n ...

What is the best way to manage Page Refresh using Angular.js?

I recently followed the tutorial at http://scotch.io/bar-talk/setting-up-a-mean-stack-single-page-application This guide went over controllers and services using angular.js for a single-page application. However, when I try to directly access /pageName o ...