Alex Kumbhani Alex Kumbhani - 1 month ago 17
AngularJS Question

why it need to double click first time to load jquery?

when i try to open popup on button click it is not open on first click.
i use J Query with Angular js for open right side popup on button click but i got problem for open it . on button click event i wrote this code .

when i click on this button

<a type="button" class="btn border-button cd-btn" ng-click="Bookservice(item)">Book</a>


$scope.Bookservice=function(item)
{
$('.cd-btn').on('click', function(event){
event.preventDefault();
$('.cd-panel').addClass('is-visible');
});
//clode the lateral panel
$('.cd-panel').on('click', function(event){
if( $(event.target).is('.cd-panel') || $(event.target).is('.cd-panel-close') ) {
$('.cd-panel').removeClass('is-visible');
event.preventDefault();
}
});
}


and popup code something like this

<div class="cd-panel from-right">
<a href="#0" class="cd-panel-close">Close</a>
<div class="cd-panel-container">
<div class="cd-panel-content">


from this code i try to open popup when i click on button at that time it use previous code which i wrote , but it is not open on first click when i click second time on button at that time open popup. so , i want that my popup must be open on first click after page load .

Thanks

Answer

You are attaching click event when Bookservice(item) is called.

Put $('.cd-panel').addClass('is-visible'); this in Bookservice function.

$scope.Bookservice=function(item)
{
     $('.cd-panel').addClass('is-visible');
     //clode the lateral panel
     $('.cd-panel').on('click', function(event){
     if( $(event.target).is('.cd-panel') || $(event.target).is('.cd-panel-close') ) { 
        $('.cd-panel').removeClass('is-visible');
        event.preventDefault();
      }
   });
}
Comments