@angular/platform-browser#SafeUrl TypeScript Examples
The following examples show how to use
@angular/platform-browser#SafeUrl.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: safe.ts From youpez-admin with MIT License | 6 votes |
/**
* Transform
*
* @param value: string
* @param type: string
*/
transform(value: string, 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:
return this._sanitizer.bypassSecurityTrustHtml(value)
}
}
Example #2
Source File: safe.pipe.ts From nica-os with MIT License | 6 votes |
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}`);
}
}
Example #3
Source File: safe.pipe.ts From open-genes-frontend with Mozilla Public License 2.0 | 6 votes |
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 "styleUrl":
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
return this.sanitizer.bypassSecurityTrustStyle(`url(${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}`);
}
}
Example #4
Source File: SafePipe.ts From geonetwork-ui with GNU General Public License v2.0 | 6 votes |
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}`)
}
}
Example #5
Source File: grafana-graph.component.ts From models-web-app with Apache License 2.0 | 6 votes |
private generateIframeUrl(config: GrafanaIframeConfig): Observable<SafeUrl> {
return this.grafana.getDasbhboardUrlFromUri(config.dashboardUri).pipe(
catchError(error => {
this.graphLoadError = error;
return throwError(error);
}),
map((url: string) => {
// replace /d/ with /d-solo/
let iframeUrl = url.replace('/d/', '/d-solo/');
// add the query params
iframeUrl = `${iframeUrl}?orgId=${this.grafana.orgId}`;
iframeUrl = `${iframeUrl}&panelId=${config.panelId}`;
iframeUrl = `${iframeUrl}&refresh=${config.refresh}s`;
iframeUrl = `${iframeUrl}&theme=light`;
for (const key in config.vars) {
if (config.vars.hasOwnProperty(key)) {
iframeUrl = `${iframeUrl}&${key}=${config.vars[key]}`;
}
}
return this.sanitizer.bypassSecurityTrustResourceUrl(iframeUrl);
}),
);
}
Example #6
Source File: grafana-graph.component.ts From models-web-app with Apache License 2.0 | 5 votes |
public iframeUrl: SafeUrl;
Example #7
Source File: dashboard.component.ts From digital-bank-ui with Mozilla Public License 2.0 | 5 votes |
getSafeUrl(url: string): SafeUrl {
this.customerPortrait = url;
return this.domSanitizer.bypassSecurityTrustUrl(url);
}
Example #8
Source File: image.component.ts From digital-bank-ui with Mozilla Public License 2.0 | 5 votes |
getSafeUrl(url: string): SafeUrl {
this.objectUrl = url;
return this.domSanitizer.bypassSecurityTrustUrl(url);
}
Example #9
Source File: customer.detail.component.ts From digital-bank-ui with Mozilla Public License 2.0 | 5 votes |
safeUrl: SafeUrl;
Example #10
Source File: customer.detail.component.ts From digital-bank-ui with Mozilla Public License 2.0 | 5 votes |
getSafeUrl(url: string): SafeUrl {
this.objectUrl = url;
return this.domSanitizer.bypassSecurityTrustUrl(url);
}
Example #11
Source File: avatar-cropper.component.ts From onchat-web with Apache License 2.0 | 5 votes |
async crop(): Promise<ImageCropData> {
let blob: Blob, src: string | SafeUrl;
// 此处需要调用imageCropper的一些私有方法,使用 any 绕过编译器检查
const imageCropper = this.imageCropper as SafeAny;
// 如果支持离屏画布,并且当前允许裁剪
if (
'OffscreenCanvas' in window &&
imageCropper.sourceImage?.nativeElement &&
imageCropper.transformedImage
) {
const worker = new Worker(new URL('../../../workers/image-cropper.worker', import.meta.url), { type: 'module' });
// 解构出需要的属性/方法
const {
format,
cropper,
transform,
transformedSize,
backgroundColor,
transformedImage,
containWithinAspectRatio,
maintainAspectRatio,
aspectRatio,
} = imageCropper;
const imagePosition = imageCropper.getImagePosition();
const width = imagePosition.x2 - imagePosition.x1;
const height = imagePosition.y2 - imagePosition.y1;
let imageBitmap: ImageBitmap;
try {
imageBitmap = await lastValueFrom(this.imageService.createImageBitmap(transformedImage));
} catch (e) {
worker.terminate();
return { blob, src };
}
return new Promise<ImageCropData>((resolve, reject) => {
worker.onmessage = ({ data }) => {
blob = data.blob;
src = this.sanitizer.bypassSecurityTrustUrl(URL.createObjectURL(blob));
this.imageCropper.imageCropped.emit(data);
worker.terminate();
resolve({ blob, src });
};
worker.onerror = () => {
worker.terminate();
reject({ blob, src });
}
worker.postMessage({
format,
cropper,
transform,
aspectRatio,
imageBitmap,
resizeCanvas,
imagePosition,
backgroundColor,
transformedSize,
maintainAspectRatio,
containWithinAspectRatio,
quality: imageCropper.getQuality(),
resizeRatio: imageCropper.getResizeRatio(width, height),
offsetImagePosition: imageCropper.getOffsetImagePosition(),
}, [imageBitmap]);
this.imageCropper.startCropImage.emit();
});
}
const { base64 } = this.imageCropper.crop();
blob = base64ToFile(base64);
src = this.sanitizer.bypassSecurityTrustUrl(URL.createObjectURL(blob));
return { blob, src };
}
Example #12
Source File: avatar-cropper.component.ts From onchat-web with Apache License 2.0 | 5 votes |
/**
* 关闭自己
* @param data 需要传回一个image src
*/
dismiss(data?: SafeUrl) {
super.dismiss(data);
}
Example #13
Source File: media.component.ts From capture-lite with GNU General Public License v3.0 | 5 votes |
readonly src$ = new ReplaySubject<SafeUrl>(1);
Example #14
Source File: chart-sidebar.component.ts From Bridge with GNU General Public License v3.0 | 5 votes |
albumArtSrc: SafeUrl = ''
Example #15
Source File: logo-config.component.ts From halstack-angular with Apache License 2.0 | 5 votes |
sanitizeImageUrl(imageUrl: string): SafeUrl {
return this.sanitizer.bypassSecurityTrustUrl(imageUrl);
}
Example #16
Source File: image-crop.component.ts From ASW-Form-Builder with MIT License | 5 votes |
safeImgDataUrl?: SafeUrl | string;
Example #17
Source File: ngx-gallery-preview.component.ts From ngx-gallery-9 with MIT License | 5 votes |
src: SafeUrl;
Example #18
Source File: ngx-gallery-preview.component.ts From ngx-gallery-9 with MIT License | 5 votes |
getSafeUrl(image: string): SafeUrl {
return image.substr(0, 10) === 'data:image' ?
image : this.sanitization.bypassSecurityTrustUrl(image);
}
Example #19
Source File: channel.component.ts From qd-messages-ts with GNU Affero General Public License v3.0 | 5 votes |
captchaImageResource: SafeUrl;
Example #20
Source File: platformBrowser.spec.ts From ngx-dynamic-hooks with MIT License | 5 votes |
bypassSecurityTrustUrl(value: string): SafeUrl {
throw new Error('Method not implemented.');
}