![](/img/trans.png)
[英]How to use <mat-progress-bar> in .ts while calling the API service using angular
[英]How to use DOMSANITIZER(bypassSecurityTrustUrl) while calling the API
在調用 API 以獲取數據時獲取 XSS 漏洞。 所以試圖添加DOMSANITIZER
,但它失敗了。 試過下面的代碼,請給我建議解決方案。
this.http.get(this.domSanitizer.bypassSecurityTrustUrl(dataUrl),{headers:headers}).subscribe(response => {
this.persons = response.data.map(x=>({...x,check:false,test:x.firstName}));
this.dtTrigger.next();
});
您可以通過以下方式在使用 API 時使用 DOMSANITIZER。
import { Component, OnInit, ViewChild, SecurityContext, } from '@angular/core'; import {DomSanitizer} from '@angular/platform-browser';
const dataUrl = this.domSanitizer.sanitize( SecurityContext.RESOURCE_URL, this.domSanitizer.bypassSecurityTrustResourceUrl( 'https://raw.githubusercontent.com/l-lin/angular-datatables/master/demo/src/data/data.json' ) ); this.http.get(dataUrl).subscribe((response) => { this.persons = response.data.map((x) => ({ ...x, check: false, test: x.firstName, })); this.dtTrigger.next(); });
重要的:
此代碼適用於您的 stackblitz 網址。
我也保存了,你可以去那里查看。 https://stackblitz.com/edit/column-names-as-tooltip-wcw1f7?file=app%2Fapp.component.ts
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.