Санитарная обработка в Angular
I have a child model that has an attribute photoPath
export interface Child {
chIld: number;
firstName: string;
photoPath?: string;
photos: Photo[];
}
I am trying to sanitize the photoPath to bypass angular security
export class ChildrenCardComponent implements OnInit {
@Input() children: Child;
public imgurl: Child["photoPath"];
constructor(private sanitizer: DomSanitizer) {
this.sanitizer.bypassSecurityTrustResourceUrl(this.imgurl)
}
ngOnInit(): void {
}
}
Путь вызывается и назначается, как видно (public imgurl: Child["photoPath"];) в массиве
HMTL вызывает imgurl, как показано ниже:
<img [src]="imgurl >
1 ответ
Решено
@Input() children: Child;
public imgurl: any;
constructor(public sanitizer: DomSanitizer) {
}
ngOnInit(): void {
this.imgurl=this.sanitizer.bypassSecurityTrustResourceUrl(this.children.photoPath)
}