Bijoy Alfred
Bijoy Alfred

Reputation: 43

dynamically creating multiple dropdown in angular js

I have an issue in dynamically creating select dropdown in angular js, changing one dropdown option make changes on the rest of the dropdowns. My requirement is to use same data option in all dropdown and to get the selected option in each dropdown. How do I over come this problem?

example:

  <div ng-repeat ="option in options">
   <select class="form-control input-lg" ng-model='newcategory.option'
   ng- change="optsChanged()"required ng-options='option.value as option.name for option
   in useroptions'>
   </select> 
  <div>

I need to create a dropdown for each row of a table that has the same options, but it should be a different instance or different model to be assigned dynamically.

Upvotes: 2

Views: 3058

Answers (1)

harishr
harishr

Reputation: 18055

use the index as the subscript for the ng-model ng-model='newcategory.option[$index]'.. currently you are using the same ng-model for all the select boxes which is causing the issue

   <div ng-repeat ="option in options">
       <select class="form-control input-lg" ng-model='newcategory.option[$index]'
            ng-change="optsChanged()"required ng-options='option.value as option.name for    option in useroptions'>
       </select> 
  <div>

Upvotes: 4

Related Questions