3

I am using bootstrap 3 CSS only without bootstrap js or jQuery with AngularJs framework, But I have a very basic usage issue which is ng-clicknot get fired on bootstrap dropdown

HTML

<div class="fc-couponThumbnail">

<i class="icon-ok" ng-if="coupon.couponMainImage=='couponThmub1'"></i>
<div class="dropdown">
    <button  type="button" class="dropdown-toggle" >
        <span class="caret"></span>
    </button>
    <ul class="dropdown-menu"  >
        <li ><a ng-click="coupon.couponMainImage='couponThmub1';">set main image</a></li>
        <li><a ng-click="coupon.couponThmub1=''">delete</a></li>
    </ul>
</div>

as I am not using bootstrap js so I made this directive to get dropdown toggled

angular.module('FansCoupon').directive('dropdownToggle', function () {
return{
    restrict:'C',
    link:function(scope,ele,attrs){

        ele.on('click', function () {
                ele.parent().toggleClass('open')

        })
        ele.on('blur', function () {
            ele.parent().removeClass('open')
        })
    }
}
})

Edit I

When I instantiate .dropdown with open class the ng-click work properly!

Edit II

calling a function instead of do javascript directly in ng-click didn't worked too.

Peter Wilson
  • 4,150
  • 3
  • 35
  • 62
  • Could you try and call a method instead? E.g. 'showHideCoupon()' or something, not convinced about doing assignment in ng-click directly is a good idea – cYrixmorten Mar 30 '16 at 11:08
  • tried this but it still doesn't working :( – Peter Wilson Mar 30 '16 at 11:10
  • http://stackoverflow.com/questions/23093291/angular-ng-click-does-not-work-in-bootstrap-drowdown-menu – rejo Mar 30 '16 at 11:17
  • @fljs Thanks for your comment, the link you provided is not related to my issue the issue of this link is about using filters and ng-repaet in bootstrap dropdown which I am not using at all plus I am not working with jQuery or bootstrap js – Peter Wilson Mar 30 '16 at 11:21

1 Answers1

1

Finally the solution for my issue was to use Angular UI Bootstrap which handling all bootstrap components as angular Js directives so I used uib-dropdown,uib-dropdown-toggle and uib-dropdown-menu

and my code now looks like :

<div class="dropdown" uib-dropdown >
<button  type="button" uib-dropdown-toggle class="dropdown-toggle" >

    <span class="caret"></span>
</button>
<ul class="dropdown-menu" uib-dropdown-menu >
    <li ><a ng-click="coupon.couponMainImage=coupon.couponThmub4;">set main image</a></li>
    <li><a ng-click="coupon.couponThmub4=''">delete</a></li>
</ul>
Peter Wilson
  • 4,150
  • 3
  • 35
  • 62
  • You could try escaping the quotes if you want, that might also make the first one work: `ng-click="coupon.couponThumb4=\"\""`. Also, is it `Thumb` or `Thmub`? – cst1992 Mar 31 '16 at 11:44
  • @cst1992 thanks for your reply! .. my issue is the ng-click not fired even if I called a function instead of write any expressions – Peter Wilson Mar 31 '16 at 11:52