本文整理汇总了TypeScript中@angular/platform-browser.DomSanitizer.bypassSecurityTrustStyle方法的典型用法代码示例。如果您正苦于以下问题:TypeScript DomSanitizer.bypassSecurityTrustStyle方法的具体用法?TypeScript DomSanitizer.bypassSecurityTrustStyle怎么用?TypeScript DomSanitizer.bypassSecurityTrustStyle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular/platform-browser.DomSanitizer
的用法示例。
在下文中一共展示了DomSanitizer.bypassSecurityTrustStyle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getLevelStyle
public getLevelStyle(): SafeStyle {
let level = this.device.Level;
let safeStyle: SafeStyle = this.sanitizer.bypassSecurityTrustStyle( `width: 0%`);
if(this.device.SwitchType === 'Dimmer' && (this.device.Data === 'On' || this.device.Data.startsWith('Set Level')))
safeStyle = this.sanitizer.bypassSecurityTrustStyle( `width: ${level}%`);
else if(this.device.Data === 'On')
safeStyle = this.sanitizer.bypassSecurityTrustStyle( `width: 100%`);
return safeStyle;
}
示例2: transform
transform(sentiment: Sentiment): string|SafeStyle {
if (!sentiment) {
return '';
}
let style = '';
// Change font based on positive/negative score.
if (sentiment.score >= 0.9) {
style += `font-family: 'Bonbon', 'Roboto', 'Helvetica', sans-serif;`;
} else if (sentiment.score >= 0.5) {
style += `font-family: 'Crafty Girls', 'Roboto', 'Helvetica', sans-serif;`;
} else if (sentiment.score <= -0.9) {
style += `font-family: 'Creepster', 'Roboto', 'Helvetica', sans-serif;`;
} else if (sentiment.score <= -0.5) {
style += `font-family: 'Julee', 'Roboto', 'Helvetica', sans-serif;`;
}
// Make bold if the magnitude is greater than 1.
if (sentiment.magnitude >= 1) {
style += `font-weight: bold;`;
}
return style ? this.sanitizer.bypassSecurityTrustStyle(style) : '';
}
示例3: 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}`);
}
}
示例4: 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);
}
示例5: 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}`);
}
}
示例6: constructor
constructor(
navParams: NavParams,
tagIndexService: TagIndexService,
settings: Settings,
sanitizer: DomSanitizer,
private navCtrl: NavController,
private wikiPageService: WikiPageService) {
this.tag = navParams.get("tag");
tagIndexService.getFilesForTag(this.tag)
.then(fileNames => this.pageNames = fileNames.map(x => wikiPageService.getPageNameFromFile(x)));
this.styleGrey = settings.getStyle() === "Grey";
this.fontPctStyle = sanitizer.bypassSecurityTrustStyle("font-size: " + settings.getFontSize() + "%");
}
示例7: makeDialogStyles
makeDialogStyles(): SafeStyle {
const width: string = this.width ? `width: ${this.width};` : ''
const styles: string = `top: ${this.top};${width}`
return this.sanitizer.bypassSecurityTrustStyle(styles)
}
示例8: transform
transform(style) {
return this.domSanitizer.bypassSecurityTrustStyle(style);
}
示例9: transform
transform(value: any): any {
return this.sanitizer.bypassSecurityTrustStyle(value);
}
示例10: sanitizeImage
public sanitizeImage(image: string): SafeStyle {
return this._sanitizer.bypassSecurityTrustStyle('url(' + image + ')');
}
示例11: transform
transform(style): SafeStyle {
return this.sanitizer.bypassSecurityTrustStyle(style);
}
示例12: ngOnChanges
public ngOnChanges(changes: {[propName: string]: SimpleChange}): void {
let val = this.resource.properties.rgbValue;
this.style = this.sanitizer.bypassSecurityTrustStyle(
'background:rgb(' + val[0] + ',' + val[1] + ',' + val[2] + ')');
}
示例13: transform
transform(value: any, args: any[]): any {
return this.santizier.bypassSecurityTrustStyle(value);
}
示例14: transform
/**
* Sanitizes the string allowing it to be injected into a template
* @param style String to sanitize
* @return Sanitized string
*/
public transform(style: string): any {
return this.sanitizer.bypassSecurityTrustStyle(style);
}
示例15: constructor
constructor(private sanitizer: DomSanitizer) {
this.backgroundImage = this.sanitizer.bypassSecurityTrustStyle(`url('${images.background}')`);
}