Dsapp
Dsapp

Reputation: 49

Adding Angular directive to dompurify element

Is it possible to add an Angular directive to an anchor tag sanitized by Dompurify?

I’ve tried adding my directive to the element, but I am unable to get the directive to be triggered. If I wrap the anchor tag with a div tag, the directive triggers just fine.

Upvotes: 0

Views: 103

Answers (1)

Eliseo
Eliseo

Reputation: 58019

The sort answer is not unless you use Angular elements (are a bit complex and generally it's better use another approaches). But "imposible is nothing". If the only you need is "capture" a "click" (see, eg. this SO) If it's more complex, you can use as inspiration this SO. In this last SO we replace the [name_of_variable] by inputs with ngModel

You can use some similar to replace by the directive

If you see the code you "split" the html string in an array of objects in the way

{
  index:a number
  text:some data
}

The .html loop over the array so according the "index" you show the text or another tag or directive

  <span *ngIf="dat.index==-1">{{dat.text}}</span>
  <input *ngIf="dat.index!=-1" [(ngModel)]="values[dat.index]">

You can create an array of elements in the way

{
  type:number
  data:string
}

And loop over the array to create a text or a directive

Upvotes: 0

Related Questions