为 [(ngModel)] 输入赋值

Assign a value to a [(ngModel)] input

这里是 MEAN 堆栈的新手,

我正在尝试将数据插入 MongoDB,但是使用连接用户的 _id,所以我有一个显示它的函数:

  getSessionInfos(){
    return sessionStorage.getItem('id'); 
  }
db.collection('transactions').insertOne({
       date : req.body.date,
       titre: req.body.titre,
       description : req.body.description,
       montant : "-" + req.body.montant,
       id: req.body.id, <-------------
       type: "debit"

所以我心想,好吧,我要创建一个以 ID 作为值的隐藏输入,这样会更容易:

<input type="text" [(ngModel)]="data.id" value="getSessionInfos()">

除了那个 NO,你似乎不能改变 NGmodel 输入的值, 那我该怎么做呢?

非常感谢

<input [hidden]='true' type="text" [(ngModel)]="data?.id" >
<ng-container *ngfor="let dataa in data"><input [hidden]='true' type="text" [(ngModel)]="dataa.id" (change)="getSessionInfos()"></ng-container>
data: any = {
  date: "",
  titre: "",
  description: "",
  montant: "",
  id: sessionStorage.getItem('id'),
  type: ""
}