I've been able to construct the image url without receiving the sanitizer errors, but my background image still will not show up. Do I have to access the "changingThisBreaksApplicationSecurity" property for this image to show properly? Any help with this is greatly appreciated.
UPDATE:
It seems wrong to access this property in the markup, but it works.
Reference the actual property changingThisBreaksApplicationSecurity
since you need to get the url string.
In order to get a row resouce URL of safeValue
object, DomSanitizerImpl.sanitize()
function may be used:
...
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) {}
I created a STACKBLITZ to demonstrate it, please look at console.logs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With