The idea:
<h2 *ngIf="tag == 'h2'"></h2>
<h3 *ngIf="tag == 'h3'"></h3>
<p *ngIf="tag == 'p'"></p>
I want to get the tag
be dynamic, depending on the tag property value.
The tag
is an Input()
parameter
P.S.: I have tried to do:
<{{tag}></{{tag}}>
, but it gives and error and is not working
<div (mouseenter)="setEditMode()" [innerHTML]="result | safeHtml" *ngIf="!editMode"></div>
<div (mouseleave)="setViewModeIfNotFocused()" *ngIf="editMode">
<input type="text" [(ngModel)]="content" #inputEl>
</div>
-
import { Component, Input, OnInit, ViewChild } from '@angular/core';
@Component({
selector: 'ui-edit-field',
templateUrl: 'edit-field.component.html'
})
export class UiEditFieldComponent implements OnInit {
@ViewChild('inputEl')
public inputEl: any;
@Input('tag')
public tag: string;
@Input('classes')
public classes: string;
@Input('content')
public content: string;
public result: string;
public editMode = false;
constructor() {
}
ngOnInit() {
this.result = '<' + this.tag + ' class="' + this.classes + '">' + this.content + '</' + this.tag + '>';
}
setEditMode() {
this.editMode = true;
}
setViewModeIfNotFocused() {
if (true) {
this.editMode = false;
}
}
}