2

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.

9
  • Do you mean make them all the same and if one changes the others reflect same value? Question is very vague Commented Jul 12, 2014 at 14:13
  • I did some edits in my question Commented Jul 12, 2014 at 15:01
  • I did some edits in my question and added a few lines of code Commented Jul 12, 2014 at 15:07
  • 1
    still not clear what your issue is. Can you create a demo in jsfiddle.net or plnkr.co Commented Jul 12, 2014 at 15:15
  • here i added the code: plnkr.co/edit/2m9uErhRAbyo7vDUCF9m?p=preview Commented Jul 12, 2014 at 16:41

1 Answer 1

4

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.