angular - Angular 11 - 我无法显示本地存储中的值
问题描述
我希望本地存储中的值显示在我的输入字段中。这是我的尝试,但它不起作用。
ts
this.additionalID = parseInt(localStorage.getItem('some-key'));
this.formValueWebinar.controls['user_id'].setValue(this.additionalID);
html
<mat-form-field class="webinarTitleInput " appearance="outline">
<mat-label class="font">Enter User ID</mat-label>
<input type="text" matInput placeholder="User ID" formControlName='user_id' [innerHtml]= 'this.additionalID'>
</mat-form-field>
解决方案
尝试使用补丁值
this.formValueWebinar.controls['user_id'].patchValue(this.additionalID);
有时 setValues 函数不会更新它只是在代码上设置的值,也不会更新尝试使用补丁
推荐阅读
- postgresql - Travis - 嵌套 jo 中的 Postgresql
- python-3.x - 为matplotlib底图中的一些投影制作透明地图
- vuetify.js - Vuetify v-select - 为多选设置默认值
- django - 在 IIS 服务器上运行 django 站点时出现问题
- javascript - 在字符串中的特定字符之前添加一个字符(JS)
- .net - 在 .net-core 中选择 onchange 到 Controller 的 Action
- powershell - GitLab - 写主机:找不到命令
- python - 在 Pandas 中将多个 DataFrame 列压缩为单个指标列
- flutter - Flutter Bloc - 事件不重新创建页面
- node.js - js中的密码问题