本文整理汇总了TypeScript中@angular/platform-browser.DomSanitizer.bypassSecurityTrustUrl方法的典型用法代码示例。如果您正苦于以下问题:TypeScript DomSanitizer.bypassSecurityTrustUrl方法的具体用法?TypeScript DomSanitizer.bypassSecurityTrustUrl怎么用?TypeScript DomSanitizer.bypassSecurityTrustUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular/platform-browser.DomSanitizer
的用法示例。
在下文中一共展示了DomSanitizer.bypassSecurityTrustUrl方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: transform
transform(value: any, context?: SecurityContext | string | String) {
if (!value) {
return value;
}
if (typeof context === "undefined") {
context = SecurityContext.HTML;
}
if (context instanceof String) {
context = context.toString();
}
if (typeof context === "string" || context instanceof String) {
context = SecurityContext[context.replace("-", "_").toUpperCase()];
}
switch (context) {
case SecurityContext.HTML:
return this.domSanitizer.bypassSecurityTrustHtml(value);
case SecurityContext.RESOURCE_URL:
return this.domSanitizer.bypassSecurityTrustResourceUrl(value);
case SecurityContext.SCRIPT:
return this.domSanitizer.bypassSecurityTrustScript(value);
case SecurityContext.STYLE:
return this.domSanitizer.bypassSecurityTrustStyle(value);
case SecurityContext.URL:
return this.domSanitizer.bypassSecurityTrustUrl(value);
}
return this.domSanitizer.sanitize(context as SecurityContext, value);
}
示例2: transform
public transform(
value: any,
type: string
): SafeHtml | SafeStyle | SafeScript | SafeUrl | SafeResourceUrl {
switch (type) {
case "html":
return this.sanitizer.bypassSecurityTrustHtml(
`${value}`.replace(/<p[^>]*>/g, "").replace(/<strong[^>]*>/g, "")
);
case "text":
const span = document.createElement("span");
span.innerHTML = value;
return span.textContent || span.innerText;
case "style":
return this.sanitizer.bypassSecurityTrustStyle(value);
case "script":
return this.sanitizer.bypassSecurityTrustScript(value);
case "url":
return this.sanitizer.bypassSecurityTrustUrl(value);
case "resourceUrl":
return this.sanitizer.bypassSecurityTrustResourceUrl(value);
default:
throw new Error(`Invalid safe type specified: ${type}`);
}
}
示例3: constructor
// #docregion trust-url
constructor(private sanitizer: DomSanitizer) {
// javascript: URLs are dangerous if attacker controlled.
// Angular sanitizes them in data binding, but we can
// explicitly tell Angular to trust this value:
this.dangerousUrl = 'javascript:alert("Hi there")';
this.trustedUrl = sanitizer.bypassSecurityTrustUrl(this.dangerousUrl);
// #enddocregion trust-url
this.updateVideoUrl('PUBnlbjZFAI');
}
示例4: transform
public transform(value: any, type: string): SafeHtml | SafeStyle | SafeScript | SafeUrl | SafeResourceUrl {
switch (type) {
case 'html': return this.sanitizer.bypassSecurityTrustHtml(value);
case 'style': return this.sanitizer.bypassSecurityTrustStyle(value);
case 'script': return this.sanitizer.bypassSecurityTrustScript(value);
case 'url': return this.sanitizer.bypassSecurityTrustUrl(value);
case 'resourceUrl': return this.sanitizer.bypassSecurityTrustResourceUrl(value);
default: throw new Error(`Invalid safe type specified: ${type}`);
}
}
示例5: Blob
this.gridContext.gridToCsv().then(csv => {
const blob = new Blob([csv], {type : 'text/plain'});
const win: any = window; // avoid TS errors
this.csvExportUrl = this.sanitizer.bypassSecurityTrustUrl(
(win.URL || win.webkitURL).createObjectURL(blob)
);
// Fire the 2nd click event now that the browser has
// information on how to download the CSV file.
setTimeout(() => $event.target.click());
});
示例6: ngOnInit
ngOnInit(){
//this.v1cleaned = this.sanitizer.bypassSecurityTrustUrl('//www.youtube.com/embed/FQSSsmTroMk');
//this.v1 = this.v1cleaned.changingThisBreaksApplicationSecurity;
this.v1 = this.sanitizer.bypassSecurityTrustUrl('youtube.com/embed/FQSSsmTroMk');
const VIDEOS: Video[] = [
{ Title: "Church Window Cookies", EmbedUrl: '//www.youtube.com/embed/FQSSsmTroMk' },
{ Title: "Pasta with Meat Sauce", EmbedUrl: '//www.youtube.com/embed/_MIdbZml6r4?list=UUpLxEusuFWB8cZXyiXs4qew' },
{ Title: "Pizza", EmbedUrl: '//www.youtube.com/embed/i9QToeYHTmQ' },
{ Title: "Kale Salad", EmbedUrl: '//www.youtube.com/embed/1eqjq_eoeQM' },
{ Title: "Maple Syrup Snow Candy", EmbedUrl: '//www.youtube.com/embed/5e5MUxhmBWk' },
];
this.videos = VIDEOS;
}
示例7: toSafeUrl
private toSafeUrl(iconPath: string): SafeUrl {
return this.sanitizer.bypassSecurityTrustUrl(iconPath);
}
示例8: sanitizeUrl
sanitizeUrl(url: string) {
return this.sanitizer.bypassSecurityTrustUrl(url);
}
示例9:
ads.map(async ad => {
const img = await this.imgcache.getCachedFile(ad.app_imageurl);
ad.app_imageurl = this.sanitizer.bypassSecurityTrustUrl(img) as string;
return ad;
}),
示例10: transform
transform(value: any): any {
return this.sanitizer.bypassSecurityTrustUrl(value);
}