Currently, I am attempting to dynamically create a select option using Renderer2. Unfortunately, I am facing difficulties in creating the <Select></Select>
element, but I can confirm that the <options>
are being successfully created. Due to certain limitations, I regret that I am unable to share all of the code snippets.
The main issue revolves around the fact that the select element is not being created, and only the first element of the array is being displayed. However, when I console log it in ngOnInit()
, I am able to see all elements without any errors popping up on the console.
Please find attached.
https://i.stack.imgur.com/VB2nq.png
I humbly request assistance and guidance in this matter. If possible, could someone provide a working demo or steer me in the right direction? After spending numerous hours researching, I stumbled upon this resource only.
arr= ["AAA", "BBB", "CCC", "DDD", "EEE"];
const select = this._rend.createElement('select');
select.name = name;
var option = this._rend.createElement('option');
this._rend.appendChild(select, option);
this._rend.appendChild(option, document.createTextNode(''));
arr.forEach( aaaa=>{
option = this._rend.createElement('option');
this._rend.appendChild(option, document.createTextNode(aaaa));
if (aaaa === value)
option.selected = true;
this._rend.appendChild(select, option);
})
Please feel free to share alternative solutions if you deem mine inadequate.
A heartfelt thank you to everyone willing to assist.