Rajesh Vishnani
Rajesh Vishnani

Reputation: 91

ng-click on span inside the ons-list-item not working

I have an ons-list with list items and an icon on it, when someone clicks on list item it should go to screen A and when i click on the icon, it should go to screen B, but the problem is ng-click conflicts as we click on the icon, technically list item is also gets clicked. Please see the code below.

<div ng-controller="getUserContacts">
<ons-list-header>Select Contact</ons-list-header>
<ons-list style="margin: -1px 0">   
    <div ng-show="loading" class="loading"><img src="img/loading.gif" height="50px" width="50px"></div>
    <ons-list-item modifier="" class="list-item" ng-repeat="x in contacts track by $index" style="margin-left: 10px;" ng-click="setcontact(x); page.pushPage('sendmoney2.html', {animation: 'slide'});">                    
        <ons-row>                           
            <ons-col width="52px" style="padding: 10px 0 0 0;">
                <img src="img/red.png" height="42px" width="42px"/>
            </ons-col>
            <ons-col>
                <header>
                    <span class="item-title">{{x.name}}</span>
                    <span class="list-item-note-sendmoney1"  ng-click="page.pushPage('editContact.html', {animation: 'slide'});"><ons-icon icon="ion-ios-information-outline" size="28px"></ons-icon></span>
                </header>
                <p class="swipe-item-desc">{{x.phone}}</p>
            </ons-col>                              
        </ons-row>                      
    </ons-list-item>
</ons-list>
</div>

Thanks.

Upvotes: 2

Views: 587

Answers (1)

Cosmin Ababei
Cosmin Ababei

Reputation: 7072

Just stop the event propagation and you should be fine. Add $event.stopPropagation() to your second ng-click like this:

ng-click="page.pushPage('editContact.html', {animation: 'slide'});$event.stopPropagation()"

Here's a more in depth explanation about the magic behind event bubbling and capturing.

Upvotes: 4

Related Questions