The interesting thing is that it is a dynamic component that can iterate html attributes and style.
We know that [ngStyle] needs a json object with properties of type css.
I have not seen in angular an [ngAtrributes] that needs a json object with attributes.
The idea and goal is to create dynamic html elements to be able to render.
Thinking about a dynamic form is not a good idea because I would lack elements such as a div, img, etc.
I tried with this approach: https://stackoverflow.com/a/48481199/9420442
It's very good, but it has a missing one, how could I enter text inside the tags ?, for example: <div> Hello world! </ Div> how could I enter 'Hello world!' with this proposal?
The main one I want is this:
HTML:
<{{tag.tagName}} *ngFor="let tag in tags"
[ngStyle]="tag.style"
[ngAtrr]="tag.atrributes">
{{tag.text}}
</{{tag.tagName}}>
TS:
this.tags = [
{
tag: 'div',
atrributes: [
{'class': 'text-center'}
],
'style': [
{'back-ground-color': 'red'},
{'color': 'blue'}
],
'text': 'Hello World!'
},
{
tag: 'input',
type: 'number'
atrributes: [
{'max': '10'},
{'place-holder': 'hello hello!'}
],
'style': [
{'back-ground-color': 'red'},
{'color': 'blue'}
],
'value': '100'
}
];
This is what I expect. Could you help me a little on how to achieve this functionality?
<div class="text-center">Hello World!</div>
<input type="number" placeHolder="hello world" max="10" value="100"></input>