Sag*_*dte 0 javascript ngfor angular angular5
我有以下来自api的回复
[
{
"Cinema_strName":"dfdsfsd, Ahmedabad",
"Cinema_strID":"HIWB",
"Cinema_strBannerImg":"F&BCombo.jpg",
"cinema_addr":"fsdfsdfr,Drive-in Road, 380052, ",
"cinema_loc":"<iframe src=\"fsdfsdfdsfsfdsfdsffsf4!2i768!4f13.1!3m3!1m2!1s0x0%3A0x6a9f5938cfed5cd2!2sCarnival+Cinemas!5e0!3m2!1sen!2sin!4v1467809324170\" width=\"600\" height=\"450\" frameborder=\"0\" style=\"border:0\" allowfullscreen></iframe>",
"cinema_mob":0
}
]
Run Code Online (Sandbox Code Playgroud)
我想从api获取iframe并附加到div map
为此,我在TS文件中写道
this.common.createAPIService('api/cinemas/List?CityName='+city, '').subscribe((result: any) => {
if(result.length){
this.cinema = result;
console.log(this.cinema);
}else{
alert('Cinema not found');
}
})
Run Code Online (Sandbox Code Playgroud)
html模板:
<div class="map" *ngFor="let map of cinema">
<div [innerHTML]="map.cinema_loc"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
但是HTML并没有出现,但如果我正常绑定,就像下面那样
<div class="map" *ngFor="let map of cinema">
<div>{{map?.cinema_loc}}</div>
</div>
Run Code Online (Sandbox Code Playgroud)
iframe以文本格式显示.
我如何附加为HTML?
请帮忙.
根据我在下面尝试过的解决方案
this.common.createAPIService('api/cinemas/List?CityName='+city, '').subscribe((result: any) => {
if(result.length){
this.cinema = result;
this.cinema = this.sanitizer.bypassSecurityTrustHtml(this.cinema);
console.log(this.cinema);
}else{
alert('Cinema not found');
}
Run Code Online (Sandbox Code Playgroud)
但是不起作用.如果我console.log this.cinema.cinema_loc.未定义.
我认为这会奏效.第一个解决方案是
<ng-container *ngFor="let testString of testStrings">
<label [innerHtml]="testString"></label>
</ng-container>
Run Code Online (Sandbox Code Playgroud)
和第二个解决方案是:
this.testString = this.sanitizer.bypassSecurityTrustHtml(this.testString);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
897 次 |
| 最近记录: |