3

在我的组件中,我从 REST 获得响应,但无法在下拉列表中填充相同的响应。

零件:

jobTitleList() {
    this.jobList = this.getJobList().then((result) => {
        this.jobList = result;
        console.log('result is : ', this.jobList );
    });
}

在控制台上我得到:结果是: ["Software Developer","Support Engineer"]

HTML选择/下拉:

 <select (focus)="jobTitleList()">
   <option *ngFor="let jobTitle of jobList" value="">{{jobTitle}}</option>
 </select>

我的屏幕上出现空的选择框。请帮忙。我关注了很多帖子,但没有帮助。提前致谢。

4

1 回答 1

1
job: IJob;
jobList: IJob[];

jobTitleList() {
    this.getJobList().then(result => {
        this.jobList = result;
    });
}

<select [(ngModel)]="job" (focus)="jobTitleList()">
   <option *ngFor="let j of jobList" [value]="j">{{ j }}</option>
</select>
于 2017-10-07T09:33:25.443 回答