I'm creating an pipe in Angular 6 that return an textbox if pass some conditions. Because inputs are not safe.. I'm using the bypassSecurityTrustHtml to work around this problem. Now I have another problem.. it shows the textbox but I can't write to it or change it. Doesn't look disable but I can't select it and change anything. Anyone knows whats going on? Thanks!!
import { Pipe, PipeTransform } from '@angular/core';
import { validateConfig } from '@angular/router/src/config';
import { TYPED_NULL_EXPR } from '@angular/compiler/src/output/output_ast';
import { SafeHtml, DomSanitizer } from '@angular/platform-browser';
@Pipe({
name: 'appConvertElement',
pure: false
})
export class ConvertElementPipe implements PipeTransform {
constructor( private _sanitizer: DomSanitizer) { }
transform(text: string, field: string) {
return this.ConvertValue(text, field);
}
private ConvertValue(text: string, field: string) {
let transformText = text;
if (condition)
return this.createTextBox(text,field);
}
return transformText;
}
createTextBox(text,id) {
let textBox = document.createElement('input');
textBox.type = 'text';
textBox.setAttribute("value", text);
textBox.id = id;
textBox.name = id;
textBox.value = text;
textBox.title = text;
// return textBox.outerHTML;
return this.safeHTML(textBox.outerHTML);
}
safeHTML(v: string): SafeHtml {
return this._sanitizer.bypassSecurityTrustHtml(v);
}
}
the html is:
<div [innerHTML]="value | appConvertElement: field"></div>