• AngularJS ng-click on li icon

    I have this code

    <div  ng-repeat="names in mitypes  = (mitype | filter:{parentid:0}:true)"> 
    
        <li ng-click="newObject[names.id]=!newObject[names.id]">
          <label ng-click="selectedlist[names.id]=!selectedlist[names.id]">{{names.id}}  </label>
        </li>
    
        </div>
       </div>
    

    Its tree of elements is ul li. Therefore, I want to have 2 events: 1. Click on the button to open / close the tree branch 2. Click the ng-click label to select the node tree

    Element

    li has css style:

    li {
      list-style-type: none; 
      background-repeat: no-repeat;
      background-position: left center;
    }
    li.closed
    {
      background-image: url(1.png);
    }
    li.opend
    {
      background-image: url(2.png);
    }
    

    I want to click on a png image to open / close and a label to select a node. Now, when you click on any part of "li", both variables change their meaning.

    How can I share these events? thanks in advance...

    +1
    source share
    1 answer

    This is the standard behavior of event propagation in browsers.

    Try $event.stopPropagationon <label>:

    <label ng-click="selectedlist[names.id]=!selectedlist[names.id]; $event.stopPropagation()">{{names.id}}  </label>
    

    , , padding-left <li>:

    li {
     list-style-type: none; 
     background-repeat: no-repeat;
     background-position: left center;
     border: 1px solid white;
     border-radius:5px;
     background-color:lightblue;
     padding-left: 30px; //add padding
    }
    

    DEMO

    +1

    All Articles