My angular5 project receives a full set of HTML content from the API side and I am displaying it as it is.Now, After it loads, I need to select some div elements where on its onClick it will apply selection box around that specific div.I am not able to inject the click event from the typescript file.Can anyone help with this? Below is the code I used to render the HTML to view. Thanks in advance.
import {Component, OnInit, Pipe, PipeTransform, ElementRef, Renderer2}
from '@angular/core';
import {SurveyFormPreviewService} from './survey-form-preview.service';
import {DomSanitizer} from '@angular/platform-browser';
@Pipe({name: 'safeHtml'})
export class SafeHtmlPipe implements PipeTransform {
constructor(private sanitized: DomSanitizer) {}
transform(value) {
console.log(this.sanitized.bypassSecurityTrustHtml(value))
return this.sanitized.bypassSecurityTrustHtml(value);
}
}
@Component({
selector: 'app-survey-form-preview',
template: '<div [innerHTML]="htmlString | safeHtml"></div>',
styleUrls: ['./survey-form-preview.component.css']
})
export class SurveyFormPreviewComponent implements OnInit {
htmlString: SafeHtmlPipe;
constructor(private surveyFormPreview: SurveyFormPreviewService, private elementRef: ElementRef,
private renderer: Renderer2, private elRef: ElementRef
) {
this.getSurveyFormPreview(1);
}
getSurveyFormPreview(surveyId: number): void {
surveyId = 5;
this.surveyFormPreview.getPreview(surveyId)
.subscribe(
resp => {
this.htmlString = resp["html"];
},
error => console.log(error));
}