Reputation: 643
I am new to angular. I am trying to add icons/input tags based on value entered into the model.
e.g. i have a model seat
<input ng-model ="seat" > //lets say user enters 3
i want to dynamically generate three models as
<input ng-model="seat.seat1">
<input ng-model="seat.seat2">
<input ng-model="seat.seat2">
Thanks in advance ..
Upvotes: 3
Views: 49
Reputation: 23234
Initial $scope.seats
in Controller:
$scope.seats = [];
And add below code to Template:
<input ng-model="seats.length">
<input ng-repeat="seat in seats track by $index" ng-model="seats[$index]">
when change the seats.length
to 3
, it will add null to array temporarily.
$scope.seats // [null, null, null]
So must to use track by $index
to avoid same value issue
Upvotes: 2
Reputation: 2400
Use ng-repeat and repeat the loop till the model value and inside that create the models.
Upvotes: 1