Reputation: 23
In my Angular2 app, I have a *ngFor
loop to show model names coming from JSON.
The parent template code looks like this
<div *ngFor="#model of datajson.models">
<models [data]="model"></models>
</div>
Now for the child component, the code looks like this
@Component({
selector: 'models',
template: `
{{data.modelname}}
<input type="text" class="txt-dev-number" [(ngModel)]="devCount"/>
`,
Here in the last line, I have a text box for each model name which will take numbers. Question is how to get the sum of all the values in the text boxes.
Upvotes: 0
Views: 1845
Reputation: 8731
You can add a count property to your model in order to bind the devCount to it.
see the below plunker example:
http://embed.plnkr.co/ct6gdEAGOvblvDZxN0gp/
Upvotes: 1