0

我有一个具有属性 photoPath 的子模型

export interface Child {
    chIld: number;
    firstName: string;
    photoPath?: string;
    
    photos: Photo[];
}

我正在尝试清理 photoPath 以绕过角度安全性

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 >
4

1 回答 1

0

解决

 @Input() children: Child;
  
  public imgurl: any;
  
  

  constructor(public sanitizer: DomSanitizer) { 
   
  }

  ngOnInit(): void {
     this.imgurl=this.sanitizer.bypassSecurityTrustResourceUrl(this.children.photoPath)
 
  }
于 2021-06-02T16:37:34.700 回答