'Edit value for a key in a Map in Angular

I have a model that uses a Map for eg: (I also have other properties such as Name)

export class User {
    _id!: string;
    accounts!: Map<String,Number>;
}

My mongoose model is:

var User = mongoose.model('user', {
    accounts : {
        type: Map,
        of: Number
    }
},'user');

I'd like to make editable for the frontend user

<div>
      <label>Accounts :</label>
      <div *ngFor="let account of userService.selectedUser.accounts | keyvalue">
        <label>Name: {{account.key}}</label>
        <input type="number" name="accountValue" #name="ngModel" [ngModel]="account.value" (ngModelChange)="account.value = $event" required>
      </div>
</div>

The key-value pairs show up in the browser but after submitting, all other properties get updated in MongoDB except for the map.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source