Search code examples
javascriptangularjspopoverangular-strap

Functions like onBeforeShow not working in angular-strap popover


I am using angular-strap popover. http://mgcrea.github.io/angular-strap/#/popovers

The documentation says if onBeforeShow function is provided, it should be invoked before the popover is shown. But that isn't working for me.

<div class="bs-docs-section" ng-controller="PopoverDemoCtrl">      
  <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3">
    <div id="popoverId" bs-popover data-trigger="hover" on-before-show="shouldBeCalledBeforePopover()" data-content-template="demo.html" delay="200" data-placement="bottom-right">
      Hover over me!!!
    </div>
  </div>      
</div>

$scope.shouldBeCalledBeforePopover = function(){
   alert("Before popover");
}

The alert does not happen.

Here is the plunker http://plnkr.co/edit/R8mRXSAcXW5KKmKDwGPS?p=preview


Solution

  • Okay here is too late but am posting.

    Plunker

    It will help in future replace your code with below snippet

    <div id="popoverId" bs-popover data-trigger="hover" bs-on-before-show="shouldBeCalledBeforePopover" data-content-template="demo.html" delay="200" data-placement="bottom-right">
    Hover over me!!!
    </div>
    

    If you take a look I have just changed the way of init function

    If you using angular-strap you have to make sure every time when you use callback functions you have to init function by bs- attr

    Thanks