尝试在AngularJS中显示图像时遇到DomSanitizer
的问题。
不知道我是否错误地存储了path
sanitizing
!
我收到此错误:
WARNING: sanitizing unsafe URL value sanitizeImg(C:/xampp/htdocs/ImagenesCompras/rubros/informatica.jpg)
HTML代码:
<div class="col-xl-2 col-md-3 col-sm-3 col-xs-4 f-category" *ngFor="let rubro of rubros">
<div class="inner">
<a [routerLink]="['/mostrarPropiedad', rubro.id]">
<span class="imgBox">
<img src="sanitizeImg({{rubro.fotoPath}})" class="img-responsive" alt="img">
</span>
<h6> {{rubro.titulo}}</h6>
</a>
</div>
</div>
角度组件
constructor(private rubrosService: RubrosServiceService,
private router: Router,
private _sanitizer: DomSanitizer) { }
ngOnInit() {
this.rubrosService.GetAllRubros().subscribe(
rubros => this.rubros = rubros,
);
}
sanitizeImg(url): SafeUrl{
return this._sanitizer.bypassSecurityTrustUrl(url);
}