I’m very new to angular and i’m having trouble with using values acquired from the HTLM side, in simple operations in the JS side.
in the HTML, this is a sample of what i have
which should palce values inside the array of numbers
as they’re selected.
<input type="radio" value="0" [(ngModel)]="numArray[0]">
<input type="radio" value="1" [(ngModel)]="numArray[0]">
<input type="radio" value="0" [(ngModel)]="numArray[1]">
<input type="radio" value="1" [(ngModel)]="numArray[1]">
<input type="radio" value="0" [(ngModel)]="numArray[2]">
<input type="radio" value="1" [(ngModel)]="numArray[2]">
and then in JS it sums the values of the array like so:
for(let i=0;i<this.phq4_qs.length;i++){
sum += numArray[i];
}
console.log(`Sum result ${this.sum}`);
but the console in the web page returns a sequece of number instead of the actual sum, like “000” instead of “0” or “101” instead of “2”.
I would like to know what am i doing wrong, and if there is better way to do so.
Thanks in advance.
Lucas Petronetto is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.