Angular:img src中的“警告:清理不安全的URL值”

时间:2018-08-29 23:24:09

标签: angular url angular-dom-sanitizer

尝试在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);
   }

0 个答案:

没有答案