我是没有AngularJS经验的Angular 2的新手,并且正在编写一个涉及设置iframe src属性的教程:
<iframe width="100%" height="300" src="{{video.url}}"></iframe>
Run Code Online (Sandbox Code Playgroud)
这引发了一个异常:
Error: unsafe value used in a resource URL context
at DomSanitizationServiceImpl.sanitize...
Run Code Online (Sandbox Code Playgroud)
我已经尝试过使用绑定但iframe
没有成功.我可能错过了一些东西,我很难找到解决方案.
风格如
<div [style.background-image]="\'url(\' + image + \')\'">Background</div>
<div [style.transform]="rotate(7deg)"
Run Code Online (Sandbox Code Playgroud)
不再添加
我该怎么做这样的事情:
$sce.trustAsResourceUrl('URL_HERE');
在全球范围内,就像在主应用程序config()
或run()
函数中一样,任何iFrame,img src等都URL_HERE
可以使用吗?
文档在解释这一点时相当差.
我想获得谷歌地图链接,显示位于纬度/经度的标记中的标题/内容.
所以参数是标题,内容,纬度,经度.结果是这样的链接 https://maps.google.com/?ie=UTF8&ll=xxx,xxx&title=xxx&content=xxx
我搜索谷歌并没有在谷歌API中找到答案,事件.
我收到以下错误:
Angular 2 - EXCEPTION:错误:资源URL上下文中使用的不安全值
是否与在启动时不立即使用媒体项目有关?或者它与URL不安全有关?我正在努力消毒它.
export class HomeComponent {
sanitizer: DomSanitizationService;
errorMessage: string;
activeMedia: MediaItem = new MediaItem(0, '', '', '', '', '', '');
constructor(
private mediaStorage: MediaStorageService,
private harvesterService: HarvesterService,
sanitizer: DomSanitizationService) {
this.sanitizer = sanitizer;
// Initial call -
harvesterService.getMediaItems(10, 'type', 'category');
let subscription = harvesterService.initialMediaHarvestedEvent.subscribe(() => {
this.activeMedia = mediaStorage.mediaList[0];
let newURL = this.activeMedia.URL + '?rel=0&autoplay=1';
newURL = newURL.replace('watch?v=', 'v/');
this.activeMedia.URL = newURL; //sanitizer.bypassSecurityTrustUrl(newURL);
console.log(newURL);
});
}
cleanURL(oldURL: string): SafeResourceUrl {
return this.sanitizer.bypassSecurityTrustUrl(oldURL);
}
}
Run Code Online (Sandbox Code Playgroud)
模板代码是: …
我有以下 HTML 代码
<iframe #originalUrl [hidden]="!showOriginalDoc" [src]="originalUrl"><span *ngIf="originalUrl===''">Original URL Not Available</span></iframe>
Run Code Online (Sandbox Code Playgroud)
以下角度代码
if(data.originalResearch.originalUrl===null)
this.originalUrl='';
else
this.originalUrl = this.domSanitizer.bypassSecurityTrustResourceUrl(data.originalResearch.originalUrl);
Run Code Online (Sandbox Code Playgroud)
上面的代码仍然抛出以下错误:
CuratorModalBodyComponent.html:123 错误错误:在 DomSanitizerImpl.vendor../node_modules/@angular/platform-browser/@angular的资源 URL 上下文中使用了不安全的值(参见http://g.co/ng/security#xss) /platform-browser.es5.js.DomSanitizerImpl.sanitize (platform-browser.es5.js?ffb0:3992) at setElementProperty (core.es5.js?0445:9398) at checkAndUpdateElementValue (core.es5.js?0445:9318) ) at checkAndUpdateElementInline (core.es5.js?0445:9252) at checkAndUpdateNodeInline (core.es5.js?0445:12357) at checkAndUpdateNode (core.es5.js?0445:12303) at debugCheckAndUpdateNode (core.es5.js?0445) :13167) 在 debugCheckRenderNodeFn (core.es5.js?0445:13146)
我正在使用 angular 4.4.1