component.html
<div *ngIf="flagArray[i].showDiv == true>
<div id=div1 [innerHTML]="getContent(data.name)"></div>
</div>
component.ts
constructor() {
this.selectedIndex = -1;
this.flagArray[0].showDiv = true;
this.dataArray = [
{name: 'Account Type', content: 'id=accntType', tag :'<div>Hello
<app-accountType></app-accountType></div>'}
]
for(let i=1; i<this.dataArray.length; i++){
this.flagArray[i].showDiv = false;
}
}
getContent(name): any {
for(let p of this.dataArray) {
console.log(" Value of Id >>"+name+ " Value of p"+p.name);
if (p.name === name) {
document.getElementById('accnttype').innerHTML='<div>Hello--<app-accountType></app-accountType></div>';
}
}
}
account.component.ts
@Component({
selector: 'app-accountType',
templateUrl: '../accountType/accountType.component.html',
})
account.component.html
<div>Hell from Account Type </div>
我添加了html的div标签和.ts文件中的方法。我正在尝试加载到html文件中。在Html文件中,应该用app-accountType compoment中的实际代码替换。