我在填充频道字段方面遇到了困难,这是md-select的一部分,我在进行websocket调用后在preInit函数中评估和填充channel数组,
<bunch of imports>
@Component({
selector : 'app-ipmi',
template : `
<md-select name="channel" placeholder="Channel" (change)="switchChannel()" options = "channels">
</md-select>
<entity-form [conf]="this"></entity-form>
`,
providers : [ TooltipsService ],
})
export class IPMIComponent {
@Input('conf') conf: any;
<bunch of variable declarations>
public channels = [];
public fieldConfig: FieldConfig[] = [
{
...
},
.....,
];
constructor(...) {}
preInit(entityEdit: any) {
entityEdit.isNew = true;
this.ws.call('ipmi.query', []).subscribe((res) => {
for (let i = 0; i < res.length; i++) {
this.channels.push({label: res[i].channel, value: res[i].channel})
}
});
}
}
答案 0 :(得分:0)
<md-select>
应包含<md-option>
元素,要显示基于channels
数组的选项,您可以使用*ngFor
指令迭代它,例如*ngFor="let channel of channels"
。所以你的HTML应该是这样的:
<md-select name="channel" placeholder="Channel" (change)="switchChannel()">
<md-option *ngFor="let channel of channels" [value]="channel.value">
{{channel.label}}
</md-option>
</md-select>