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.

4
  • 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 Commented Mar 30, 2016 at 11:08
  • tried this but it still doesn't working :( Commented Mar 30, 2016 at 11:10
  • stackoverflow.com/questions/23093291/… Commented Mar 30, 2016 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 Commented Mar 30, 2016 at 11:21

1 Answer 1

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>
Sign up to request clarification or add additional context in comments.

2 Comments

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 thanks for your reply! .. my issue is the ng-click not fired even if I called a function instead of write any expressions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.