New to Kendo UI for AngularStart a free 30-day trial

Using Kendo Angular Components with NgModules

NgModules are a core concept in Angular that provide a modular approach to building applications. They allow you to group related code together, manage dependencies, encapsulate functionality, etc.

As of v17.0.0, NgModules are no longer used as default configuration for new applications. For more details, refer to the Pros and Cons of NgModules and Standalone Components.

This guide provides the information on how to use the Kendo UI for Angular component with NgModules.

The following example demonstrates the Grid in NgModule-based app.

Change Theme
Theme
Loading ...

Installing the Component

You can choose to use either of the following two approaches for installing the Kendo UI for Angular package and the styles you want to apply:

Quick Setup with Angular CLI

The quick setup presents an automatic approach for adding packages with Angular CLI through the ng-add command. Suitable for saving time and efforts as ng-add executes in a single step a set of otherwise individually needed commands.

To add the Kendo UI for Angular package when using NgMogules, run the following command. Replace grid and GridModule with any other package name and module:

sh
ng add @progress/kendo-angular-grid

As a result, the ng-add command will perform the following actions:

  • Add the @progress/kendo-angular-grid package as a dependency to the package.json file.
  • Import the GridModule in the current application's main module.
  • Register the Kendo UI Default theme in the angular.json file.
  • Add all required peer dependencies to the package.json file.
  • Trigger npm install to install the theme and all peer packages that are added.

Manual Setup

The manual setup provides greater visibility and better control over the files and references installed in your Angular application. You can install the required peer dependencies and a Kendo UI theme by running separate commands for each step and import the desired component modules in your NgModule.

  1. Install the Grid package together with its dependencies. Check the dependencies in the Dependencies and Standalone Utilities page of each package. The following command installs the Grid and its dependencies.

    sh
     npm install --save @progress/kendo-angular-grid @progress/kendo-angular-dropdowns @progress/kendo-angular-treeview @progress/kendo-angular-inputs @progress/kendo-angular-dateinputs @progress/kendo-data-query @progress/kendo-angular-intl @progress/kendo-angular-l10n @progress/kendo-angular-label @progress/kendo-drawing @progress/kendo-angular-excel-export @progress/kendo-angular-buttons @progress/kendo-angular-common @progress/kendo-angular-pdf-export @progress/kendo-angular-popup @progress/kendo-licensing @progress/kendo-angular-icons @progress/kendo-angular-layout @progress/kendo-angular-utils
  2. Add the import of the component in your NgModule.

    • When adding a package with single component (like Grid), import its respective module. For more details check the available components and modules:

      ts
      import { NgModule } from '@angular/core';
      import { BrowserModule } from '@angular/platform-browser';
      import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
      import { GridModule } from '@progress/kendo-angular-grid';
      import { AppComponent } from './app.component';
      
      @NgModule({
          imports: [BrowserModule, BrowserAnimationsModule, GridModule],
          declarations: [AppComponent],
          bootstrap: [AppComponent]
      })
      
      export class AppModule {}
    • When adding a package with multiple components (like Inputs package) you can import all at once (InputsModule) or import only the components in use. For more details check the available components and modules:

      ts
      import { NgModule } from '@angular/core';
      import { BrowserModule } from '@angular/platform-browser';
      import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
      import { TextBoxModule } from '@progress/kendo-angular-inputs';
      import { AppComponent } from './app.component';
      
      @NgModule({
          imports: [BrowserModule, BrowserAnimationsModule, TextBoxModule],
          declarations: [AppComponent],
          bootstrap: [AppComponent]
      })
      
      export class AppModule {}
  3. The next step is to style the component by installing one of the available Kendo UI themes—Kendo UI Default, Kendo UI Material, Kendo UI Bootstrap, or Kendo UI Fluent.

    3.1 To start using a theme, install its package through NPM.

    • Default theme

      sh
      npm install --save @progress/kendo-theme-default
    • Bootstrap theme

      sh
      npm install --save @progress/kendo-theme-bootstrap
    • Material theme

      sh
      npm install --save @progress/kendo-theme-material
    • Fluent theme

      sh
      npm install --save @progress/kendo-theme-fluent

    3.2 After the theme package is installed, reference it in your project. You can include kendo-themes in your project in one of the following ways:

Using the Component

  1. After successfully installing the Grid package and importing its module, add the following code in the app.component.html file:

    html
    <kendo-grid [data]="gridData">
        <kendo-grid-column field="ProductID" title="ID"> </kendo-grid-column>
        <kendo-grid-column field="ProductName" title="Name"> </kendo-grid-column>
        <kendo-grid-column field="Category.CategoryName" title="Category"> </kendo-grid-column>
        <kendo-grid-column field="UnitPrice" title="Price"> </kendo-grid-column>
    </kendo-grid>
  2. Bind the data property to an object array in the app.component.ts file:

    ts
    public gridData: Product[] = [
        {
            ProductID: 1,
            ProductName: 'Chai',
            UnitPrice: 18,
            Category: {
                CategoryID: 1,
                CategoryName: 'Beverages'
            }
        },
        {
           /*...*/
        }
    ];
  3. Build and serve the application by running the following command in the root folder.

    sh
    ng serve
  4. Point your browser to http://localhost:4200 to see the Kendo UI for Angular Grid component on the page.

Activating Your License Key

As of December 2020, using any of the UI components from the Kendo UI for Angular library requires either a commercial license key or an active trial license key. If your application does not contain a Kendo UI license file, activate your license key.

List of Available Kendo Modules

You can import the entire package module or the modules of the components in use. The following tables show the modules each package exports:

Single Component Modules

The following table lists the packages with single components.

ComponentModule
ChartsChartsModule
EditorEditorModule
Excel ExportExcelExportModule
FilterFilterModule
GanttGanttModule
GridGridModule
ListBoxListBoxModule
ListViewListViewModule
MapMapModule
NotificationNotificationModule
PagerPagerModule
PDF ExportPDFExportModule
PDFViewerPDFViewerModule
PivotGridPivotGridModule
PopupPopupModule
ProgressBarsProgressBarsModule
RippleRippleModule
SchedulerSchedulerModule
ScrollViewScrollViewModule
SortableSortableModule
SpreadsheetSpreadsheetModule
ToolbarToolbarModule
TreeListTreeListModule
TreeViewTreeViewModule
TypographyTypographyModule

Multiple Component Modules

The following table lists the packages with multiple components.

ComponentModule
BarcodesBarcodesModule, BarcodeModule, QRCodeModule
ButtonsButtonsModule, ButtonModule, ButtonGroupModule, ChipModule, DropDownButtonModule, FloatingActionButtonModule, SplitButtonModule
ConversationalUIConversationalUIModule, ChatModule, AIPromptModule
DateInputsDateInputsModule, CalendarModule, DateInputModule, DatePickerModule, DateRangeModule, DateTimePickerModule, MutliViewCalendarModule, TimePickerModule
DialogsDialogsModule, DialogModule, WindowModule
DropdownsDropDownsModule, AutoCompleteModule, ComboBoxModule, DropDownListModule, DropDownTreesModule, MultiSelectModule, MultiColumnComboBoxModule
GaugesGaugesModule, ArcGaugeModule, CircularGaugeModule, LinearGaugeModule, RadialGaugeModule
IconsIconsModule, IconModule, SVGIconModule
IndicatorsIndicatorsModule, BadgeModule, LoaderModule, SkeletonModule
InputsInputsModule, CheckBoxModule, ColorPickerModule, FormFieldModule, MaskedTextBoxModule, NumericTextBoxModule, RadioButtonModule, RangeSliderModule, SignatureModule, SwitchModule, SliderModule, TextAreaModule, TextBoxModule
LabelsLabelModule, FloatingLabelModule
LayoutLayoutModule, AvatarModule, CardModule, DrawerModule, ExpansionPanelModule, GridLayoutModule, PanelBarModule, SplitterModule, StepperModule, StackLayoutModule, TabStripModule, TileLayoutModule, TimelineModule
MenusMenusModule, MenuModule, ContextMenuModule
NavigationNavigationModule, AppBarModule, BottomNavigationModule, BreadCrumbModule
TooltipsTooltipsModule, TooltipModule, PopoverModule
UploadsUploadsModule, UploadModule, FileSelectModule
UtilitiesUtilsModule, DragAndDropModule

NgModules vs Standalone Components: Pros and Cons in Kendo UI for Angular

Both NgModules and Standalone components configurations are supported by Angular and the Kendo UI for Angular suite.

NgModules are ideal for large, complex applications that require modular organization and features like lazy loading. Standalone components are better suited for smaller, simpler projects, where reducing boilerplate code and increasing flexibility are more important.

ProsCons
NgModulesProvide a structured way to organize related components, services, pipes, and directives, making the codebase modular and maintainable. They simplify dependency injection, manage shared services, and enable lazy loading to improve performance by loading modules only when needed.Managing multiple NgModules can become complex, especially in large applications, and there is some boilerplate and overhead associated with creating and maintaining them. Circular dependencies between NgModules can also be challenging to manage and avoid
Standalone ComponentSimplify development by removing the need to declare components in NgModules, reducing boilerplate and making the codebase more lightweight. They are flexible and easily reusable across different projects, and can improve tree-shaking capabilities, potentially reducing the final bundle size. Suitable for simpler applications or specific use casesManaging dependencies and shared services can become more challenging without NgModules, and standalone components might lead to a lack of structure and organization in larger applications, making maintenance and navigation harder.

A combination of both approaches might be useful depending on the specific needs and complexity of the application.

Using NgModule-based Components in Standalone Components

NgModule-based components can also be used within a standalone component. To do this:

  1. Export your component from the module:
ts
@NgModule({
  declarations: [MyFeatureComponent],
  // export the NgModule-based component
  exports: [MyFeatureComponent],
})
export class MyFeatureModule {
}
  1. Import the NgModule containing the desired components into the standalone component's imports array. This integration allows you to use the NgModule-based components in the standalone component's template just like any other component.
ts
@Component({
  selector: "my-standalone",
  template: `This is a standalone component.`,
  standalone: true,
  // Import the NgModule that declares the component
  imports: [MyFeatureModule],
})
class StandaloneComponent {}

Using Standalone Components in NgModule-based Components

You can integrate standalone components into NgModule-based applications just like any other component.

To incorporate a standalone component within a NgModule-based application, import the standalone component in the module's declarations array. This allows the standalone component to be used throughout the module as if it were declared within the NgModule itself.

ts
@NgModule({
  declarations: [
    AppComponent,
    StandaloneComponent
  ],
  imports: [BrowserModule],
  bootstrap: [AppComponent],
})
export class AppModule {}

Learning Resources