1
findvehicleDocumentsImage(owner: string, registrationNumber: string, fileType: string): Observable<any> {
  debugger;
  return this.http.get<any>(AppConstant.FIND_VEHICLE_DOCUMENT_API+'/'+owner+'/'+registrationNumber+'/'+fileType);
}

2 Answers 2

2

To retrieve an image and display it you should create a service:

Image service

findvehicleDocumentsImage(owner: string, registrationNumber: string, fileType: string): Observable { 
  // debugger; 
  return http.get(`${AppConstant.FIND_VEHICLE_DOCUMENT_API}/${owner}/${registrationNumber}/${fileType}`,
    {
      header: {
        authentication: `Bearer ${yourToken}`
      }
    }
  );
}

Component A - TS

Then in your component, you have to call the method and render the new image.

  public image: string;

  constructor(
    private readonly domSanitizer: DomSanitizer,
    private readonly service: YourService
  ) {}
  ngOnInit() {
    this.service.findvehicleDocumentsImage(owner, registrationNumber, fileType)
    .subscribe(image => {
      // I suppose you retrieve an URL, but it depends from your data
      this.image = this.domSanitizer.bypassSecurityTrustUrl(image);    
     });
  }

Component A - HTML

<img [src]="image" />

In this way, you are retrieving, sanitizing the image, and displaying it.

Bonus tip:

You should implement an interceptor for adding the token to each of your HTTP requests. You can get more information here: Angular Interceptor

Sign up to request clarification or add additional context in comments.

Comments

0

get img url in ts file:

imageUrl:string;

show in html:

<img src={{imageUrl}} alt=""/>

1 Comment

it is asking for authentication login

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.