简体   繁体   中英

ng-checked not working for multiple condition expression in angular js template

I want to check the Users check box on selection of category. But when there is no key for Category in usr_cat array previously checked check boxes not unchecked. I want to uncheck all the users when Manager is selected in the category.

Category = [{cid:'1',name:'Head'},cid:'2',name:'Manager'}]

users = [0:{'id':10,name:'AAAAA'},{'id':12,name:'BBBBB'},{'id':13,name:'CCCCC'},{'id':14,name:'DDDDDDDD'}]

usr_cat = ['1':[10,14]]

Category List

    <ul class="list-unstyled cat-lst">
      <li ng-repeat = "cat in categery" ng-click ="selectcategry(cat.cid)>{{cat.name}} </li>
    <ul>

User List

<ul class="list-unstyled usr-lst">
  <li ng-repeat = "usr in users">
    <span class=" checkbox ">
     <input class="optionChechk " id="user_{{usr.id}}" type="checkbox" ng-checked = "{{usr_cat[sele_cid] != 'null' && usr_cat[sele_cid] != 'undefined' && usr_cat[sele_cid] != '' && (usr_cat[sele_cid].indexOf(usr.id) != -1)}}" ng-value="{{usr.id}}" >
     <label for="user_{{usr.id}}" txt = "{{usr_cat[sele_cid]}}">{{usr.name}}</label>
    </span>
  <li>
</ul>

JS

$scope.selectcategry = function(cid){
    $sele_cid = cid;
}

Hi the code contains many error

  1. Angular braces are used inside ng-attributes.
  2. improper closer of quotes"".
  3. Improper naming standards camel-casing is the format.
  4. Category is the variable you mentioned spelling categery is used everywhere.

     <ul class=""> <li ng-repeat = "cat in categery" ng-click ="selectcategry(cat.cid)">{{cat.name}}</li> </ul>
  5. Array responses are seem to inValid,suggested bellow,scope is missing in sele_cid

     $scope.categery =[{"cid":'1',"name":'Head'},{"cid":'2',"name":'Manager'}]; $scope.users = [{'id':10,"name":'AAAAA'},{'id':12,"name":'BBBBB'}, {'id':13,"name":'CCCCC'},{'id':14,"name":'DDDDDDDD'}]; $scope.usr_cat = [10,14]; $scope.selectcategry = function(cid){ $scope.sele_cid = cid; }

    please work on this

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM