Search results

Add TextBox Programmatically in Angular TextBox component

23 Sep 2021 / 1 minute to read
  • Import the Input modules from ej2-inputs library as shown below.
Copied to clipboard
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.
Source
Preview
app.component.ts
app.module.ts
main.ts
Copied to clipboard
import { Component } from '@angular/core';
import { Input } from '@syncfusion/ej2-inputs';

@Component({
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');
    Input.createInput ({
        element: element
    });

    let element1: HTMLInputElement = document.getElementById('textbox-icon');
    Input.createInput ({
        element: element1,
        buttons: ['e-input-group-icon e-input-down'],
        properties: {
            placeholder:'Enter Value'
        }
    });
}
}
Copied to clipboard
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { FormsModule } from '@angular/forms';
/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
        FormsModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
Copied to clipboard
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);