本文整理汇总了TypeScript中@angular/platform-browser.DomSanitizer.bypassSecurityTrustScript方法的典型用法代码示例。如果您正苦于以下问题:TypeScript DomSanitizer.bypassSecurityTrustScript方法的具体用法?TypeScript DomSanitizer.bypassSecurityTrustScript怎么用?TypeScript DomSanitizer.bypassSecurityTrustScript使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular/platform-browser.DomSanitizer
的用法示例。
在下文中一共展示了DomSanitizer.bypassSecurityTrustScript方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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}`);
}
}
示例2: 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);
}
示例3: 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}`);
}
}
示例4: transform
transform(value: any): any {
return this.sanitizer.bypassSecurityTrustScript(value);
}