-1

I have an issue trying to add inputs dynamically.

I have this:

<button ng-click="operations.push({})">Add input</button>

which is adding inputs:

<div ng-repeat="operation in operations">
  <input ng-model="operation.detailText">
</div>

I have 2 columns, where I have exactly the same due to an ng-repeat, so, in both columns I have the adding inputs button, When I click on the button Add input, I am adding the inputs to both columns, which I don't want, I need to add those inputs only to the current input where I am working on.

I made a video for you to see what I am talking about. Here the video

Check here for the code: jsbin

14
  • You need to put up more of your code. This is likely doing this because the alias for both controllers (for each (column?)) is the same, but we can't know for sure without more. Maybe consider making a fiddle?: jsfiddle.net Commented May 28, 2015 at 20:42
  • all I have in the controller is this $scope.operations = []; @Grallen and yes, is the same controller. Look at the video. Commented May 28, 2015 at 20:47
  • each column needs it's own controller or the controller need an element in an array for each column (multidimensional array) Commented May 28, 2015 at 20:48
  • Can you show both the ng-repeat? Commented May 28, 2015 at 20:48
  • 1
    Make a working jsfiddle for the next time so you can avoid downvotes. Commented May 28, 2015 at 21:08

1 Answer 1

2

I think you are using the same array for both the ng-repeat that is

operations

So when you click on add button it adds an empty object to operations and both the ng-repeat is affected since they both are using the same array.

You need to have different arrays, something like operations and operations1 and then write the second ng-repeat with operations1

Sign up to request clarification or add additional context in comments.

1 Comment

did you see the video ??? there are 2 boxes one above another, why those boxes needs to have different arrays or controllers if they are boxes reproduced due to a ng-repeat?. Then I have another ng-repeat because when I do click on add button, I need it to reproduce infinite amount of inputs. I thought that by doing something like $index in any part will fix my issue.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.