0

I am using Angular 9, when run ng serve is give me the error:

Property 'sanitizer' is private and only accessible within class.

My HTML Code.

<div class="img_wrp" *ngIf="hospital?.image">
     <img class="image-preview" [src]="sanitizer.bypassSecurityTrustUrl(hospital.image)">
</div>

My .ts code

import { DomSanitizer } from '@angular/platform-browser';
constructor (private sanitizer: DomSanitizer) {}

Is there something that I have miss out?

R. Richards
  • 24,603
  • 10
  • 64
  • 64
Jared Ti Lian Eng
  • 541
  • 1
  • 4
  • 9
  • 2
    The error speaks for itself. If you want to use a property in template, you should remove the `private` keyword. – developer033 Feb 27 '20 at 01:57
  • @Jared, remember that, in the .html you only can use "public" variables. So, use in constructor `constructor(public sanitizer:DomSanitizer){}` NOTE:by defect, in Angular all the variables are public – Eliseo Feb 27 '20 at 07:33

0 Answers0