我已经能够构造图像URL而没有收到消毒剂错误,但是我的背景图像仍然无法显示。我是否必须访问“ changingThisBreaksApplicationSecurity”属性才能使此图像正确显示?任何帮助,我们将不胜感激。
答案 0 :(得分:2)
请参考实际属性changingThisBreaksApplicationSecurity
,因为您需要获取url字符串。
答案 1 :(得分:0)
为了获得safeValue
对象的行资源URL,可以使用DomSanitizerImpl.sanitize()
函数:
...
import { ɵDomSanitizerImpl, DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
...
// row URL
url = 'https://www.gravatar.com/avatar/5ea793dcbaff5a5e29ad3d05ef564d86';
// safe value type URL
safeUrl = this._sanitizer.bypassSecurityTrustResourceUrl(this.url);
// sanitized back from safe value raw URL
sanitizedUrl = this._sanitizerImpl.sanitize(SecurityContext.RESOURCE_URL, this.safeUrl);
...
constructor(protected _sanitizer: DomSanitizer, protected _sanitizerImpl: ɵDomSanitizerImpl) {}
我创建了一个STACKBLITZ进行演示,请查看console.logs