Configurable input arrays in angular

I am studying Angular.js and I came up with a problem that should probably be simple, but I cannot find the answer.

I want to create form input with the value "connectedTeams", like this in html:

<input type="text" name="connectedTeam[]"> <input type="text" name="connectedTeam[]"> <input type="text" name="connectedTeam[]"> 

I tried the following in Angular ...

 <input type="text" name="connectedTeams[]" class="form-control" ng-model="user.connectedTeams"> 

... but it binds the same value to all 3 inputs. I know this makes sense, but I cannot figure out how to say that the ng model is user.connectedTeams. [] (user> connectedTeams> add to the array.

Hope this makes sense for someone to respond quickly.

+6
source share
1 answer
  ng-model="user.connectedTeams[0]" ng-model="user.connectedTeams[1]" and so on 

You can put it in ngRepeat, so you do not need to repeat your code as shown above.

FYI, the name is used only for verification in Angularjs.

+9
source

Source: https://habr.com/ru/post/981557/


All Articles