Search results

Initialize ButtonGroup using util function in Angular ButtonGroup component

25 Oct 2021 / 2 minutes to read

Though, it is a CSS component for easy initialization of ButtonGroup createButtonGroup util function can be used.

To use createButtonGroup util function, SplitButton dependencies should be configured and it should be added in system.config.js.

Using createButtonGroup method, the Button options, selector, and cssClass is passed and the corresponding classes is added to the elements.

Create basic ButtonGroup

To create a basic ButtonGroup, the target element along with the button elements should be created and createButtonGroup should be imported from ej2-splitbuttons.

Create radio type ButtonGroup

To create a radio type ButtonGroup, the target element along with the input elements should be created with type radio.

Create checkbox type ButtonGroup

Checkbox type ButtonGroup creation is similar to radio type ButtonGroup, instead the type of the input elements should be checkbox.

The following example illustrates how to create ButtonGroup using createButtonGroup function for basic, checkbox, and radio type behaviors.

Copied to clipboard
import { Component } from '@angular/core';
import { createButtonGroup } from '@syncfusion/ej2-splitbuttons';

    selector: 'app-root',
    template: `<!-- To render ButtonGroup. -->
               <h5>Normal behavior</h5>
               <div id='basic'>
                <h5>Checkbox type behavior</h5>
                <div id='checkbox'>
                    <input type="checkbox" id="checkbold" name="font" value="bold" />
                    <input type="checkbox" id="checkitalic" name="font" value="italic" />
                    <input type="checkbox" id="checkundeline" name="font" value="underline" />
                <h5>Radiobutton type behavior</h5>
                <div id='radio'>
                    <input type="radio" id="radioleft" name="align" value="left" />
                    <input type="radio" id="radiomiddle" name="align" value="middle" />
                    <input type="radio" id="radioright" name="align" value="right" />

export class AppComponent {

ngOnInit() {
createButtonGroup('#basic', {
    buttons: [
        { content: 'HTML' },
        { content: 'CSS' },
        { content: 'Javascript'}

createButtonGroup('#checkbox', {
    buttons: [
        { content: 'Bold' },
        { content: 'Italic' },
        { content: 'Undeline'}

createButtonGroup('#radio', {
    buttons: [
        { content: 'Left' },
        { content: 'Center' },
        { content: 'Right'}
Copied to clipboard
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ButtonModule } from '@syncfusion/ej2-angular-buttons';
import { AppComponent } from './app.component';
import { enableRipple } from '@syncfusion/ej2-base';


 * Module
    imports: [
    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';


If null value is passed in button options, then that particular button will be skipped from processing in createButtonGroup util function.