How to fill subcategories based on category selection in AngularJS -


i have json data this:

[ {     "id": "1",     "name": "abc",     "image": "abc.png",     "subcategories": [         {             "scid": "1",             "scname": "abc1"         },         {             "scid": "2",             "scname": "abc2"         },         {             "scid": "3",             "scname": "abc3"         }     ] }, {     "id": "2",     "name": "xyz",     "image": "xyz.png",     "subcategories": [         {             "scid": "4",             "scname": "xyz1"         },         {             "scid": "5",             "scname": "xyz2"         },         {             "scid": "6",             "scname": "xyz3"         }     ] } ] 

and trying fill categories , subcategories this:

            <tr>                 <div class="form-group">                     <td>category name</td>                     <td>                         <select class="form-control" ng-model="newproduct.category" ng-options="category category.name category in categories | orderby:['name']" required></select>                     </td>                    </div>              </tr>             <tr>                 <div class="form-group">                     <td>sub category name</td>                     <td>                         <select class="form-control" ng-model="newproduct.subcategory" ng-options="subcategory subcategory.name subcategory in categories.subcategories | orderby:['scname'] | filter:{ 'id' : newproduct.category.id }:true" required></select>                     </td>                 </div>             </tr> 

though categories filling well, no sub-categories getting filled, after selecting category.

can me wrong here?

in second ng-options say:

subcategory subcategory.name subcategory in categories.subcategories 

but categories looks array, won't have .subcategories property. instead think meant use category ngmodel on first select.

ng-model="newproduct.category"  

this leave with:

subcategory subcategory.name subcategory in newproduct.category.subcategories 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -