main.component.html
<form (submit)="onSubmit()">
height:
<input type="number" name="height" [(ngModel)]="user.height">
<br><br>
Weight:
<input type="number" name="weight"[(ngModel)]="user.weight">
<br><br>
<input type="submit">
</form>
<h5 *ngFor="let user of users">
{{user.score}}
</h5>
main.component.ts
export class MainComponent implements OnInit {
users = [];
user = {
height: 0,
weight: 0,
};
onSubmit() {
console.log(this.user.height);
console.log(this.user.weight);
var score = this.user.weight * this.user.height;
this.users.push(score);
console.log(score);
this.user = {
height: 0,
weight: 0
}
}
}
this.user.weight and this.user.height are multiplied and saved in var score. But how do I pass the var score to show in my main.component.html? I tried to push score in users array but its not showing up in my main.component.html.
scoreinuser. add it and store the calculated value to it.usersis supposed (I guess) to be an array of users (soArray<User>), but you're pushing scores to this array (of type number). You're supposed to display the score of each user, but you don't have any score in the users. Also, your code is not indented, making it very hard to read. This is all basic stuff. Learn and apply the basics.