angular - 动态角度材料“选择”标签上的 setValue 不起作用
问题描述
我有一个带有动态选项的“mat-select”标签(加载了 http)。
<mat-select placeholder="Parent" formControlName="ParentId">
<mat-option value="0">Without Parent</mat-option>
<mat-option [value]="item.id" *ngFor="let item of menuItems">{{item.title}}</mat-option>
</mat-select>
获取 menuItems 后,我setValue
的表单:
async loadFormData() {
this.menuItems = await this.menuService.getMenuItems();
if (this.itemId) {
let item = await this.menuService.getMenuItem(this.itemId);
this.addMenuItemForm.setValue({ParentId: 13});
}
}
但它不起作用。相同的代码与静态选项完美配合。
解决方案
setvalue
仅用于控件。用于patchvalue
表格。参考:https ://angular.io/guide/reactive-forms#patching-the-model-value
推荐阅读
- python - Torch 在多 GPU 设置中卡住将模型传输到 GPU
- ruby-on-rails-5 - 在 Rails 5 中与 redirect_back :fallback_location 一起使用时,警报消息会导航到其他页面
- uima - uimaFIT:建立 JCas 实例列表
- javascript - 相邻的 JSX 元素必须被封装在 react native 中
- python - 解析VCF文件并插入数据库的慢python代码
- hadoop - Hadoop distcp to S3 性能很慢
- javascript - 如何创建固定输入掩码?
- c# - DataGridViewButtonColumn 是作为第 0 列的最后一列
- java - Java Spring Boot SwaggerUI
- javascript - Javascript:如何从 servlet 获取和打印数据