Answer the question
In order to leave comments, you need to log in
How to hang events in Angular2 and access attributes for html coming from api?
Good afternoon!
There is a task to pass html with non-standard tags and attributes from Rest API to Angular2.
Once passed, Angular should be able to interact with that html. Process clicks on it, get attribute values, etc.
Tell me which way to dig?
html example:
<some-container>
<some-tag some-id="123123" >text</some-tag>
</some-container>
Answer the question
In order to leave comments, you need to log in
By means of what do you plan to process these very clicks and get attribute values?
If, for example, you will use jQuery, then this option will do:
import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser'
@Pipe({ name: 'safeHtml' })
export class SafeHtmlPipe implements PipeTransform {
constructor(private sanitized: DomSanitizer) { }
transform(value: string) {
return this.sanitized.bypassSecurityTrustHtml(value);
}
}
<div [innerHTML]="data.content | safeHtml"></div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question