我正在尝试为iframe添加src。但是,当我尝试访问SourceResourceURL时,出现一条错误消息,指出“类型'{属性不存在'mapURl'分支:字符串;地址:字符串; tel:字符串;传真:字符串;电子邮件:字符串; map_link: string;}'。ts(2339)“ ...请参阅下面的代码:
import { Component, OnInit } from '@angular/core';
import {DomSanitizer,SafeResourceUrl,} from '@angular/platform-browser';
@Component({
selector: 'app-contact',
templateUrl: './contact.page.html',
styleUrls: ['./contact.page.scss'],
})
export class ContactPage implements OnInit {
mapURl: SafeResourceUrl;
slider = [
{
branch: 'Head Office',
address: '58A Half Way Tree Road, Kingston 10',
tel: '(876) 926-3590-4 or 926-3740-6',
fax: '(876) 922-5996',
email: 'jis@jis.gov.jm',
map_link:"https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3794.44245595098!2d-76.7950062846247!3d18.0046584894462!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x8edb3fbadd465f91%3A0x2421cdae52664b88!2sJamaica%20Information%20Service!5e0!3m2!1sen!2sjm!4v1574292631365!5m2!1sen!2sjm",
},
{
branch: 'Television Department',
address: '5-9 South Odeon Avenue (Half-Way Tree), Kng 10',
tel: '(876) 922-3317 or 922-8680-2 or (876) 922-8684',
fax: '(876) 922-5996',
email: 'media@jis.gov.jm',
map_link:"https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3794.2956337390224!2d-76.80091328462457!3d18.01147858924482!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x8edb3f24924360b1%3A0x77894e7882659946!2sJamaica%20Information%20Service%20Television!5e0!3m2!1sen!2sjm!4v1574292677100!5m2!1sen!2sjm",
},
{
branch: 'Regional Office',
address: 'NHT Building 42 B-C Union Street, Montego Bay',
tel: '(876) 952-0544',
fax: '(876) 922-5996',
email: 'jis@jis.gov.jm',
map_link:"https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d2675.8308615898427!2d-77.91857756949159!3d18.474765679968364!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x8eda2a7b2092c601%3A0xb0f2a303ed0c04ea!2sNational%20Housing%20Trust%20-%20St.%20James%20Branch!5e0!3m2!1sen!2sjm!4v1574292573465!5m2!1sen!2sjm",
}
];
constructor(private sanitizer:DomSanitizer) { }
i=0;
ionViewWillEnter(): void {
for(let maps of this.slider){
this.slider[this.i].mapURl = this.sanitizer.bypassSecurityTrustResourceUrl(maps.map_link);
this.i++;
}
}
ngOnInit() {
}
}
答案 0 :(得分:0)
您可以通过以下方式访问“ mapURl”:
this.slider[this.i]['mapURl'] = this.sanitizer.bypassSecurityTrustResourceUrl(maps.map_link);
,它将重新启动此新字段。
祝你好运!!!