我有一个选择选项,其中必须在下拉列表中显示公司名称。任何人都可以帮我从安慰输出中获取HTML名称。
HTML:
<select class="form-control" id="exampleSelect1" name="selected" [(ngModel)]="selectedCampaign" >
<option *ngFor="let item of CampaignData" [ngValue]="item">{{item.campaign_name}}</option>
</select>
打字稿:
this.usersTableService.getCompanyData(this.token).subscribe(companies => {
this.data = companies;
this.companiesPDF = companies;
var CampaignData = this.companiesPDF;
console.log(JSON.stringify(companies));
});
}
安慰输出:
[ {“CVR”:3456789,“name”:“Benz”,“address”:“34 rue du bourbier”,“phoneNo”:633406546,“email”:“claire.malinet@iae-aix.com”,“有效“:真” ACCESSID “:NULL,” agreementNo “:空,” ID “:18,” postalCodeId “:NULL,” 测前“:假},
{ “CVR”:1234567, “姓名”:“斯特凡的 当地“,”地址“:”Norre Alle 8" , “PHONENO”:485698659, “电子邮件”: “stefania.b.wiredelta@gmail.com”, “主动”:真实的, “ACCESSID”:空, “agreementNo”:空, “ID”:20” postalCodeId “:NULL,” 测前“:假},
{ “CVR”:2365986, “姓名”: “Churchdesk”, “地址”:“Kobenvan 32" , “PHONENO”:25362536, “电子邮件”: “stefaniabarabas@gmail.com”, “主动”:真实的, “ACCESSID”:空, “agreementNo”:空, “ID”:23, “postalCodeId”:空“测前”:假},
{ “CVR”:78945665, “姓名”: “Peergrade”, “地址”:“Titangae 11,2200 哥本哈根”, “PHONENO”:8659865, “电子邮件”: “david@peergrade.com”, “主动”:真实的, “ACCESSID”:空, “agreementNo”:空, “ID”:25, “postalCodeId”:空“测前”:假},
{ “CVR”:85968596, “姓名”: “博世”, “地址”:“Norre Alle 7,2500 哥本哈根”, “PHONENO”:78451296, “电子邮件”: “hermagold@gmail.com”, “主动”:真实的, “ACCESSID”:空, “agreementNo”:空, “ID”:27, “postalCodeId”:空“测前”:假},
{ “CVR”:784586 “名字”: “拉拉”, “地址”:“哥本哈根 25S”, “PHONENO”:78458526, “电子邮件”: “lala@lala.com”, “主动”:真实的, “ACCESSID”:空, “agreementNo”:空, “ID”:30, “postalCodeId”:空“测前”:假},
{ “CVR”:12345678, “姓名”: “testWD”, “地址”:“Titangade 11,2200 哥本哈根 “ ”PHONENO“:34567890, ”电子邮件“: ”claire.m.wiredelta@gmail.com“, ”主动“:真实的, ”ACCESSID“:空, ”agreementNo“:空, ”ID“:37” postalCodeId “:空,” 测前“:真正}, { “CVR”:12312322, “名”: “Wirelocal”, “地址”:空, “PHONENO”:123123123, “电子邮件”: “maks.k.wiredelta@gmail.com”, “主动”:真” ACCESSID “:空,” agreementNo “:空,” ID “:38,” postalCodeId “:空,” 测前“:假}, { “CVR”:111, “名”: “AnuShree”, “地址”:空, “PHONENO”:23456, “电子邮件”: “anushree.s.wiredelta@gmail.com”, “主动”:真” ACCESSID “:NULL,” agreementNo “:空,” ID “:39,” postalCodeId “:NULL,” 测前“:假},
{ “CVR”:38185470, “姓名”: “Orbiz”, “地址”:“Lyskær 7,1。2730 位于Herlev”, “PHONENO”:20638651, “电子邮件”: “tandrup@orbizinsight.dk”, “主动”:真实的, “ACCESSID”:空, “agreementNo”:空, “ID”:40, “postalCodeId”:空“测前”:真}]
请帮忙。
答案 0 :(得分:2)
首先,您的模型应该可以访问您的模板,因此根据您的代码,使用this.data
,您可以使用data
来呈现数据。
其次,您可以像这样渲染它:
<select class="form-control" id="exampleSelect1" name="selected" [(ngModel)]="selectedCampaign" >
<option *ngFor="let item of data" [ngValue]="item">{{item.name}}</option>
</select>
答案 1 :(得分:1)
试试这个
<select class="form-control" id="exampleSelect1" name="selected" [(ngModel)]="selectedCampaign" >
<option *ngFor="let item of companiesPDF" [ngValue]="item">{{item?.name}}</option>
</select>
CampaignData
?
安全导航,这有助于避免异步数据时出错。