Reputation: 1770
I have a class MemberInfo. there is a property which is Photo. Now I would like to create a memberinfo object with property value. the code is below:
let info = new MemberInfo();
info.MemberId = "101";
info.MemberName = "Mohammad Nasir Uddin";
info.Type = "General";
info.Category = "A";
info.BloodGroup = "B+";
info.MobileNo = "012589652357";
info.Photo = this.sanitizer.bypassSecurityTrustUrl("'https://www.gravatar.com/avatar/205e460b479e2e5b48aec07710c08d50'");
info.ShopNo = "101";
info.ShopName = "Yellow Computers";
info.Floor = "First Floor";
this.selectedMember = info;
to make safe image url I have sanitized it. But it's shows the compile time error:
Type 'SafeUrl' is not assignable to type 'string'. info.Photo = this.sanitizer.bypassSecurityTrustUrl("'https://www.gravatar.com/avatar/205e460b479e2e5b48aec07710c08d50'")
to bind the photo to html I have used the below code:
<img [src]="selectedMember.Photo" class="mr-2">
How can I solve the problem?
Upvotes: 0
Views: 430
Reputation: 2663
The DomSanitizer bypassSecurityTrustUrl method returns a SafeUrl object from @angular/platform-browser namespace.
Now either modify the Photo property in MemberInfo class to be of SafeUrl type or of type any.
Thanks.
Upvotes: 1