本文整理汇总了TypeScript中@angular/platform-browser.DomSanitizer.sanitize方法的典型用法代码示例。如果您正苦于以下问题:TypeScript DomSanitizer.sanitize方法的具体用法?TypeScript DomSanitizer.sanitize怎么用?TypeScript DomSanitizer.sanitize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular/platform-browser.DomSanitizer
的用法示例。
在下文中一共展示了DomSanitizer.sanitize方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: serviceError
serviceError(json: any) {
const message = this.satinizer.sanitize(SecurityContext.HTML, json.message);
const code = this.satinizer.sanitize(SecurityContext.HTML, json.code);
const html = this.satinizer.bypassSecurityTrustHtml(`
<div class="sn-title">Error</div>
<div class="sn-content">
${message} </br>Code: ${code}
</div>
`);
return this.html(html, 'error');
}
示例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:
this.settings.getCustomPage().subscribe(x => {
x.html = this.sanitizer.sanitize(SecurityContext.HTML, this.sanitizer.bypassSecurityTrustHtml(x.html));
this.form = this.fb.group({
enabled: [x.enabled],
title: [x.title, [Validators.required]],
html: [x.html, [Validators.required]],
fontAwesomeIcon: [x.fontAwesomeIcon, [Validators.required]],
});
});
示例4: it
it('should sanitize when markedOptions.sanitize is true and no sanitizer function is provided', () => {
const markedOptions: MarkedOptions = { sanitize: true };
const mockRaw = '### Markdown-x';
const sanitized = domSanitizer.sanitize(SecurityContext.HTML, parse(mockRaw));
const unsanitized = parse(mockRaw);
expect(markdownService.compile(mockRaw, false, markedOptions)).toBe(sanitized);
expect(markdownService.compile(mockRaw, false, markedOptions)).not.toBe(unsanitized);
});
示例5: 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()];
}
return this.domSanitizer.sanitize(context as SecurityContext, value);
}
示例6: prompt
get prompt() {
const state = this.getPlugState();
// Run this when a new prompt is set.
if (this.lastPromptId !== state.id) {
this.lastPromptId = state.id;
const safeHtml =
this.sanitizer.sanitize(SecurityContext.HTML, state.message)
.replace(/ /g, '<br>'); // Convert newlines.
this.lastPromptHtml = this.sanitizer.bypassSecurityTrustHtml(safeHtml);
this.focusSelf();
if (state.default) {
this.setResponse(state.default);
}
}
return this.lastPromptHtml;
}
示例7: _readBalance
private _readBalance(data, from, json, self){
var label = "", type;
var start = data.indexOf('class="balance"', from);
if (start < 0) return;
var end = data.indexOf('</table>', start);
if (end < 0) return;
var tablehtml = data.substring(start, end);
var html = '<table>' + tablehtml.substring(tablehtml.indexOf('>')+1).replace(/\n/g,"") + '</table>';
var doc = document.implementation.createHTMLDocument("");
//doc.body.innerHTML = this.sanitizer.bypassSecurityTrustHtml(html);
doc.body.innerHTML = this.sanitizer.sanitize(SecurityContext.HTML, html).toString();
[].forEach.call(doc.querySelectorAll('thead tr th:first-of-type'), function(el) {
label = self._clean(el.innerHTML);
});
if (label.indexOf('nternet') > 0) type = "mb";
if (label.indexOf('essages') > 0) type = "texts";
if (label.indexOf('inutes') > 0) type = "mins";
if (label.indexOf('redit') > 0) type = "credit";
json[type] = {"label": label, "headings":[], "rows":[], "total":""};
var index=0;
[].forEach.call(doc.querySelectorAll('tbody tr th'), function(el) {
json[type].headings[index] = self._clean(el.innerHTML);
index++;
});
[].forEach.call(doc.querySelectorAll('tbody tr'), function(row) {
var values = [];
var index=0;
[].forEach.call(row.querySelectorAll('td'), function(el) {
values[index] = self._clean(el.innerHTML);
index++;
});
if (values && values[0]) {
if (values[0].indexOf('otal') > 0) json[type].total = values[2];
else json[type].rows.push(values);
}
});
self._readBalance(data, end+1, json, self);
}
示例8: transform
transform(html: string) : SafeHtml {
return this.sanitizer.sanitize(SecurityContext.HTML, html);
}
示例9: transform
transform(value) {
return this.sanitizer.sanitize(SecurityContext.NONE, value);
}
示例10: it
it('should store the captcha on getting new captcha', () => {
imageCaptchaService.getCaptcha.and.returnValue(of({ image: '<svg>captcha</svg>' }))
component.getNewCaptcha()
const sanitezedCaptcha = domSanitizer.sanitize(SecurityContext.HTML, component.captcha)
expect(sanitezedCaptcha).toBe('<svg>captcha</svg>')
})