Add textbox programmatically in Angular Textbox component

27 Apr 20242 minutes to read

  • Import the Input modules from ej2-inputs library as shown below.
import {Input} from '@syncfusion/ej2-inputs';
  • Pass the HTML Input element as parameter to the createInput method.

  • You can also add the icons on the input by passing buttons property value with the class name e-input-group-icon as parameter to the createInput method.

import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { FormsModule } from '@angular/forms'




import { Component } from '@angular/core';
import { Input } from '@syncfusion/ej2-inputs';

@Component({
imports: [
        
        FormsModule
    ],


standalone: true,
    selector: 'app-root',
    template: `<div class="wrap">
                <input id="textbox" type="text" placeholder="Enter Name" />
                <input id="textbox-icon" type="text" />
               </div>`
})

export class AppComponent {
    ngOnInit() {
        let element: HTMLInputElement = document.getElementById('textbox') as HTMLInputElement;
        Input.createInput ({
            element: element
        });

        let element1: HTMLInputElement = document.getElementById('textbox-icon') as HTMLInputElement;
        Input.createInput ({
            element: element1,
            buttons: ['e-input-group-icon e-input-down'],
            properties: {
                placeholder:'Enter Value'
            }
        });
    }
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));