如何在 Ng 字段中填充本地存储键值

How to populate localstorage key value in Ng Field

我有一个字段使用 Ng 指令进行所需的验证,但我想默认用我的本地存储键的值填充它 localstorage.getItem('actreel');

领域

<div class="row">
   <div class="col-8">
    <input id="batchno" type="text" (ngModel)="model.reelno" name="reelno" #reelno="ngModel" placeholder="Reel No. *" value="" required>
   </div>
   <div class="col-12 rqderror" [hidden]="reelno.valid || reelno.untouched"> 
    Reel is required
   </div>
</div>

你应该在你的 ts 控制器中的 ngOnInit 事件中感觉到它是这样的:

 ngOnInit(){
     this.actreel = localstorage.getItem('actreel');
 }

然后在你的视野中使用它:

<div class="row">
   <div class="col-8">
    <input id="batchno" type="text" [(ngModel)]="actreel" name="reelno" #reelno="ngModel" placeholder="Reel No. *" value="" required>
   </div>
   <div class="col-12 rqderror" [hidden]="reelno.valid || reelno.untouched"> 
    Reel is required
   </div>
</div>