0

Below is the HTML:

 <a [href]= "message.messagelinkHere ? sanitize(message.messagelinkHere) : message.messagelink"

in ts file

 import { DomSanitizer } from '@angular/platform-browser';

constructor(public sanitizer:DomSanitizer) { }
 sanitize(url:string) {
  let sanitizedUrl;
  sanitizedUrl = this.sanitizer.bypassSecurityTrustResourceUrl(url)
  console.log(sanitizedUrl) //SafeValue must use [property]=binding:/(https://urldefense.proofpoint.com/v2/url?u=https-3A__nam11.safelinks)
  return sanitizedUrl;
 }

trying to hit the URL it gets appended with http://localhost:4200/https://urldefense.proofpoint.com/v2/url?u=https-3A__nam11.safelinks and link is opening the local application, instead of external site.

Can you please let me know how can i remove localhost that is appended in href

user1498069
  • 124
  • 2
  • 14

1 Answers1

0

Here is the solution I did not use Dom sanitizer instead I directly kept URL using string interpolation to tag.

https://stackblitz.com/edit/angular-ivy-xe5gzz?file=src%2Fapp%2Fapp.component.html

SaiSurya
  • 1,046
  • 8
  • 14
  • i tried using without sanitizer as well, – user1498069 Apr 20 '21 at 05:17
  • Did you see the example link I posted try putting your URL there. – SaiSurya Apr 20 '21 at 05:45
  • if i use directly it works , but if i add the condition it wont work it says unsafe, i need to add the condition based on that i need to open different links as shown above – user1498069 Apr 20 '21 at 06:20
  • if we need to use that in class variable URL declared as global it will work, for some cases i get the URL on some method execution until then URL is not available, once the method is called and the URL is filled it turns out to be unsafe – user1498069 Apr 20 '21 at 07:16