我正在基于以下json创建动态表单:
[
{
"type": "text","name": "First Name","value": "","placeholder":"First Name","required": true
},{
"type": "text","name": "Last Name","placeholder":"Last Name",{
"type": "select","name": "Country","placeholder":"","required": true,"options": [
{
"name": "LL","code": "LL"
}
]
}
]
我在文本字段的最终json中获取了值,但没有在所选下拉列表中获取值:
如您所见,国家/地区
这就是我的 app.component.html 的样子
<div *ngIf="low">
<div>
<form #form="ngForm">
<div *ngFor="let input of lowPassData">
<div *ngIf="input.type == 'text'">
<label [for]='input.name'>{{input.name}}</label>
<input [type]='input.type'
[name]='input.name'
[(ngModel)]='input.value'
[placeholder]='input.value'
[required]='input.required'
class="box"
/>
</div>
<div *ngIf="input.type == 'select'">
<label [for]='input.name'>{{input.name}}</label>
<select
[(ngModel)]='input.value'
[required]='input.required'
>
<option *ngFor="let country of input.options" >{{country.name}}</option>
</select>
</div>
</div>
</form>
<button pButton type="button" label="Click" (click)="addInputs()" [disabled]="!form.valid"></button>
</div>
这是我的 .ts 文件
lowPass(){
this.lowPassData= adData;
this.low= true;
}
此处 adData 指问题的第一个json文件。
谁能建议我该怎么做