0

I am adding dropdown on click of a button . The Model of these dropdowns are same when I am adding it to DOM .

There is a list of items which is creating dropdowns using ng-repeat . This list of items are pushed with new item on button click .

Now while adding a new dropdown to the list the model is the same everytime

when I change any drop downs , it is changing all others also .

What I am looking for :

When I add a new item to the list , (that item will be shown as a dropdown on UI using ng-repeat) although the model of the item being added in the list are same, items selected in one dropdown should not reflect in other.

I understand MVC and how model updates views in angular. This might be simple , However I am finding it tough for now.

Please provide your valuable help.

<div style="border:5px solid grey;" ng-controller="myCtrl" >
 <div ng-repeat="li in list track by $index">

  <span ng-bind-html="li"></span>

 </div>

<input type="button" ng-click="addNewDropDown()" value="Add New Dropdown">

</div>

And app code is :

(function (){
var app = angular.module('ruleApp', []);

app.config(['$sceProvider', function($sceProvider) {
    $sceProvider.enabled(false);
}]);
app.controller('myCtrl', function($scope) {
$scope.names=['a','b','c','d'];
var dropdown="<select><option ng-repeat="+"x in names"+">{{x}}</option></select>";
$scope.list=[dropdown];
$scope.addNewDropDown=function(){   
    var newDD="<select><option ng-repeat="+"x in names"+">{{x}}</option></select>"; 
    $scope.list.push(newDD);
};  
});


})()
4
  • 1
    please post your code what you have tried in plunkr will be helpful to resolve your issue Commented Sep 21, 2016 at 12:16
  • Welcome to the SO my friend, it's good to post your code with your question. Commented Sep 21, 2016 at 12:28
  • I have updtaed the question and added code snippet . . Commented Sep 22, 2016 at 5:39
  • I found a similar issue later : (Please ,this is not dulcitae , just similar) stackoverflow.com/questions/31150903/… Commented Sep 22, 2016 at 12:32

0

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.