Click here to Skip to main content
15,908,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear sir/madam
i am fetching the image url from the database table and trying to show the image in tag but i am getting error:-
sanitizing unsafe URL value 

if have used
sanitizer.bypassSecurityTrustUrl()
.After that the error has been removed but the imagee is still not been shown.

here is my code of Component:-

import { Component, OnInit} from '@angular/core';
import { data } from '../Classes/edata';
import { dservice } from '../Service/dataservice';
import {DomSanitizer} from '@angular/platform-browser';
@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  
})
export class HomeComponent implements OnInit {
emp:data[];
  constructor(private _eservice:dservice , private sanitizer:DomSanitizer) 
  {
   }
   public getSantizeUrl(url:string) 
   {
     alert(url);
    return this.sanitizer.bypassSecurityTrustUrl(url);
}
  ngOnInit() {
    this.load();
  }
    load()
    {
      this._eservice.getdata().subscribe((edata)=>this.emp=edata);
    }
}


class model:-
export class data
{
    id:number;
    name:string;
    adress:string;
    pic:string;
}


Html View:-
<div class="col-md-4 col-sm-6" *ngFor="let e of emp | paginate: {itemsPerPage:5, currentPage:p}">
                          <div class="property-card card">
                              <div class="property-card-header image-box">
                                  <img src="{{e.pic}}">


Thanks For Your Help In Advance.

What I have tried:

<img [src]="getSantizeUrl(e.pic)">
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900