javascript - Trigger the click event on an element if a condition is true in Angular js -


i have angular js view.html page passing string called datadict $scope method of controller.
value {{ datadict.days }} displaying value nearly everyday , {{ datadict.days.includes('nearly everyday') }} showing result true.

here code :

 <div class="some_class">   <ul class="ex1">     <li><a ng-click ="datadict.days.includes('not applicable')" class="mdcl-tab1">not applicable</a> </li>     <li><a ng-click ="datadict.days.includes('several days')" class="mdcl-tab1">several days</a> </li>     <li><a ng-click ="datadict.days.includes('more half days')" class="mdcl-tab1">more half days</a> </li>     <li><a ng-click ="datadict.days.includes('nearly everyday')" class="mdcl-tab1">nearly everyday</a> </li>   </ul> </div> 

and when element gets clicked, event handled function :

<script> $(document).ready(function () {      $(".mdcl-tab1").on('click',function(){          $(this).addclass('tick');         $('.ex1').attr('id', 'ex1');      });  });  </script> 

the problem want trigger click event on <a> element above condition true that's why added condition ng-click ="datadict.days.includes('nearly everyday')" not getting desired result. doing wrong ?

you can this,

<script> $(document).ready(function () { $(".mdcl-tab1").on('click',function(){      $(this).addclass('tick');     $('.ex1').attr('id', 'ex1');  });  if($scope.datadict.days.includes('nearly everyday')){ $(".mdcl-tab1").trigger("click"); } }); 

and remove ng-click attribute anchor tag

<a class="mdcl-tab1"> 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -