Angular 2 Bilateral binding removes name attribute from html input tag

When I bind to two methods in the input tag, the name attribute is removed from the input tag. An anchor element is an array.

<div class="row" *ngFor="let box of boxs; let boxindex=index ">
<div class="col-sm-4">
<label>Boxs</label>
<input type="text" name="count[{{boxindex}}]" [(ngModel)]="box[boxindex]">
</div>
</div>

When I write above, the name attribute is removed, but

<div class="row" *ngFor="let box of boxs; let boxindex=index ">
<div class="col-sm-4">
<label>Boxs</label>
<input type="text" name="count[]" [(ngModel)]="box[boxindex]">
</div>
</div>

thus the name attribute remains. What is wrong in the first code? I submit this form to the Laravel route.

+4
source share
1 answer

I checked your source code like this

<div *ngFor="let box of boxs; let boxindex=index ">
  <div>
   <label>Boxs</label>
   <input #input type="text" name="count[{{boxindex}}]" placeholder={{input.name}}>
  </div>
</div>

on plunkr here , and it works, there must be something else taking out your name.

Edit

2.0.0, . , , , 2.0.0 angular let *ngFor, #

<div *ngFor="#box of boxs; #boxindex=index ">

plunkr

- 2.0.0 Angular.

+1

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


All Articles