angular


Angular 2 not showing correctly values in input


I've this component template
<!-- Some initial page code -->
<sm-modal title="Create new movement" icon="exchange" #editStorageModal>
<modal-content>
<form class="ui form error" (ngSubmit)="saveEdit()" #editStorageModalForm="ngForm">
<!-- Other stuff -->
<table class="ui celled table">
<thead>
<tr>
<th>Product</th>
<th>Amount changed (negative for removals)</th>
<th></th>
</tr>
</thead>
<tbody>
<tr *ngFor="let movement of currentStorageMovement.storage_product_movements; let i = index; trackBy:customTrackBy">
<td>
<sm-select [(model)]="movement.product_id" placeholder="Select product..." class="fluid search" [ngClass]="{loading: loadingProducts}">
<option *ngFor="let product of products" value="{{product.id}}">{{product.name}} - {{product.supplier?.name}}</option>
</sm-select>
</td>
<td>
<div class="field" [ngClass]="{error: formErrors.storage_product_movements && formErrors.storage_product_movements[i]?.amount}">
<input type="number" step="1" placeholder="Amount" [(ngModel)]="movement.amount" name="amount">
</div>
</td>
<td>
<a class="clickable" (click)="deleteProductMovement(i)"><i class="trash icon"></i></a>
</td>
</tr>
<tr *ngIf="(!storageMovements || !storageMovements.length) && !loading"><td colspan="3" class="center aligned">No storage movements yet...</td></tr>
<tr *ngIf="loading"><td colspan="3"><div class="ui active centered inline loader"></div></td></tr>
</tbody>
</table>
<div class="ui button primary" (click)="addNewProductMovement()">New product movement</div>
</form>
</modal-content>
<modal-actions>
<div class="ui button red" (click)="closeEdit()">Abort</div>
<div class="ui button green" (click)="editStorageModalForm.ngSubmit.emit()" [ngClass]="{loading: submitting}">Save</div>
</modal-actions>
</sm-modal>
when I have 2 elements in currentStorageMovement.storage_product_movements one with amount 2 and the other with amount 3 angular displays 2 inputs with both having 3 as value.
Using Augury I can se the array elements have correctly 2 and 3 as values, the input element with 3 (the one that should be 2) instead has these properties:
NgModel
value: 3
viewModel: 2
so somehow ngModel knows the value but displays something else in the input value
For reference, the modal code is this
Update: after cloning the same template outside the modal, I can see that the input outside the modal is correct, the one inside is wrong, could be because the modal uses jquery to move the dom from my template to outside the app dom element to have correct styling/positioning?
Each of the input elements has the same name attribute, which is supposed to be unique. To give each input element a unique name, you can use a {{ }} expression in its value with i as part of the expression. For example {{ "amount" + i }}.

Related Links

access key value of object
Setting class on ion-item when using *ngFor
TS2304: Cannot find name 'describe' in Webpack / Angular 2
Selectors name when naming directives
How to Authenticate Angular 2 with Firebase API using Auth0
Include user_metadata and app_metadata in JWT using Auth0
Primeng component calendar have a method for close the pop up calendar manually?
Angular test does not include import from node_modules
Convert Angular 4 web app to Angular Universal app
Generate a routing module while creating a module in angular-cli
What is the best practice to manage sessions with Ionic 2
Angular 2 Updating Component After Form Submit With New Data From Response
How to configure and use Auth-0 in Angular4
How to get meta tags work correctly in angular 2? [closed]
Angular2-highcharts switching option
How to make ViewChild work in a unit test

Categories

HOME
datatables
automation
encryption
masonry
winzip
luigi
wolfram-mathematica
attributes
custom-attributes
virtocommerce
inform7
vaadin-grid
apache-spark-2.0
javacard
url-rewriting
openmeetings
corba
sql-azure
subplot
divide-and-conquer
file-permissions
coap
ssis-2008
angle
revit
django-channels
size-classes
ext4
lwip
induction
webm
aircrack-ng
appery.io
lsmeans
nestedscrollview
quickbooks-online
sencha-architect
configuration-files
android-optionsmenu
ole
ifttt
ctags
matlab-guide
shared-ptr
dnspython
fuzzy
same-origin-policy
slug
synopsys-vcs
sonarqube-4.5
z-order
google-api-webmasters
sequencing
htsql
dotpeek
rouge
grid-layout
unreal-blueprint
mime-mail
scrapyd
sparklines
realbasic
gridsplitter
angularjs-ng-options
acronym
.a
custom-validators
ncbi
seeding
vin
google-plugin-eclipse
ember-qunit
accessdatasource
stackato
data-sharing
openacs
kiwi
cxf-client
hasp
println
stockquotes
c++builder-6
jbossws
stackmob
struts2-tiles-plugin
remotipart
cgimagesource
trusted-timestamp
jlayer
viewstack
nspasteboard
layar
rakefile
blat
windows-2000
incremental-linking
executequery
tibco-gi
itsm

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App