I am trying to add html from editpage.ts to editpage.html
editpage.ts
var strHTML = '<p [contentEditable]="contentEditable" >abc<p>';
this.possibleHTML = strHTML;
this.possibleHTML = this.possibleHTML.map(value => this._sanitizer.bypassSecurityTrustHtml(value));
editpage.html
<div id="main-wrapper">
<content *ngIf="possibleHTML">
<div [innerHtml]="possibleHTML"></div>
</content>
</div>
When this is inserted, then in developer tools, it looks like this
<h1 _ngcontent-c2>Hii<h2>
My [contentEditable]="contentEditable" attribute is gone. I need to inject HTML dynamically and I need this attribute to change text.
Edit
My component.ts:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-filemanager',
templateUrl: './filemanager.component.html',
styleUrls: ['./filemanager.component.css']
})
export class FilemanagerComponent implements OnInit {
constructor() { }
ngOnInit() {
this.document.getElementById("main-wrapper").innerHTML += "<p [contentEditable]="contentEditable" >abc<p>";
}
}
Now what I want is, my attribute should not be lost.
[innerHTML]="..."is ignored by Angular. You won't ever be able to make Angular resolve value- or event-bindings or create component for content added this way. If you want Angular you process as string as template content dynamically, you can create a component at runtime and JIT-compile it.[innerHTML]="..."