【发布时间】:2020-02-12 20:41:08
【问题描述】:
我正在尝试遍历 JSON 对象并创建 mat-form-field 输入,其中类型根据特定的 JSON 值而变化。我正在像这样迭代我的对象
<mat-form-field *ngFor="let entry of item.entry" class="form-field" appearance="outline">
<input matInput id={{entry.id}} value={{entry.value}}>
</mat-form-field>
这没问题。但是,当我像这样检查条目的格式(包含在 JSON 对象中)时......
<mat-form-field *ngFor="let entry of item.entry" class="form-field" appearance="outline">
<input matInput *ngIf="entry.format=='STRING'" id={{entry.id}} value={{entry.value}}>
<input matInput *ngIf="entry.format=='INTEGER'" id={{entry.id}} value={{entry.value}} type="number">
</mat-form-field>
我收到错误:ERROR Error: mat-form-field must contain a MatFormFieldControl.
这对我来说没有意义,因为 matInput 永远不会改变。我错过了什么吗?
这是我引用的 JSON 结构的示例:
{
"group-name":"Core",
"entry":[
{
"id":"foo",
"value":"foo",
"format":"STRING",
"label":"IP Address",
"edit":true,
"tool-tip":"Insert Host IP Address",
"hidden":false
},
{
"id":"bar",
"value":"4200",
"format":"INTEGER",
"label":"Port",
"edit":true,
"tool-tip":"Port for connections",
"hidden":false
},
]
},
有什么想法吗?
【问题讨论】:
标签: angular angular-material2 angular-forms