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.
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:
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 thepackage.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
.
-
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.
shnpm 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
-
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:
tsimport { 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:tsimport { 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 {}
-
-
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
shnpm install --save @progress/kendo-theme-default
-
Bootstrap theme
shnpm install --save @progress/kendo-theme-bootstrap
-
Material theme
shnpm install --save @progress/kendo-theme-material
-
Fluent theme
shnpm 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:- By using an external (CDN) link
- By using a precompiled CSS file
- By compiling the theme from the SCSS source files
-
Using the Component
-
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>
-
Bind the
data
property to an object array in theapp.component.ts
file:tspublic gridData: Product[] = [ { ProductID: 1, ProductName: 'Chai', UnitPrice: 18, Category: { CategoryID: 1, CategoryName: 'Beverages' } }, { /*...*/ } ];
-
Build and serve the application by running the following command in the root folder.
shng serve
-
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.
Component | Module |
---|---|
Charts | ChartsModule |
Chart Wizard | ChartWizardModule |
Editor | EditorModule |
Excel Export | ExcelExportModule |
Filter | FilterModule |
Gantt | GanttModule |
Grid | GridModule |
ListBox | ListBoxModule |
ListView | ListViewModule |
Map | MapModule |
Notification | NotificationModule |
Pager | PagerModule |
PDF Export | PDFExportModule |
PDFViewer | PDFViewerModule |
PivotGrid | PivotGridModule |
Popup | PopupModule |
ProgressBars | ProgressBarsModule |
Ripple | RippleModule |
Scheduler | SchedulerModule |
ScrollView | ScrollViewModule |
Sortable | SortableModule |
Spreadsheet | SpreadsheetModule |
Toolbar | ToolbarModule |
TreeList | TreeListModule |
TreeView | TreeViewModule |
Typography | TypographyModule |
Multiple Component Modules
The following table lists the packages with multiple components.
Component | Module |
---|---|
Barcodes | BarcodesModule, BarcodeModule, QRCodeModule |
Buttons | ButtonsModule, ButtonModule, ButtonGroupModule, ChipModule, DropDownButtonModule, FloatingActionButtonModule, SplitButtonModule |
ConversationalUI | ConversationalUIModule, ChatModule, AIPromptModule |
DateInputs | DateInputsModule, CalendarModule, DateInputModule, DatePickerModule, DateRangeModule, DateTimePickerModule, MutliViewCalendarModule, TimePickerModule |
Dialogs | DialogsModule, DialogModule, WindowModule |
Dropdowns | DropDownsModule, AutoCompleteModule, ComboBoxModule, DropDownListModule, DropDownTreesModule, MultiSelectModule, MultiColumnComboBoxModule |
Gauges | GaugesModule, ArcGaugeModule, CircularGaugeModule, LinearGaugeModule, RadialGaugeModule |
Icons | IconsModule, IconModule, SVGIconModule |
Indicators | IndicatorsModule, BadgeModule, LoaderModule, SkeletonModule |
Inputs | InputsModule, CheckBoxModule, ColorPickerModule, FormFieldModule, MaskedTextBoxModule, NumericTextBoxModule, RadioButtonModule, RangeSliderModule, SignatureModule, SwitchModule, SliderModule, TextAreaModule, TextBoxModule |
Labels | LabelModule, FloatingLabelModule |
Layout | LayoutModule, AvatarModule, CardModule, DrawerModule, ExpansionPanelModule, GridLayoutModule, PanelBarModule, SplitterModule, StepperModule, StackLayoutModule, TabStripModule, TileLayoutModule, TimelineModule |
Menus | MenusModule, MenuModule, ContextMenuModule |
Navigation | NavigationModule, AppBarModule, BottomNavigationModule, BreadCrumbModule |
Tooltips | TooltipsModule, TooltipModule, PopoverModule |
Uploads | UploadsModule, UploadModule, FileSelectModule |
Utilities | UtilsModule, 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.
Config | Pros | Cons |
---|---|---|
NgModules | Provide 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 Component | Simplify 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 cases. | Managing 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 Standalone Components in NgModule-based Components
- Using NgModule-based Components in Standalone Components
Using NgModule-based Components in Standalone Components
NgModule-based components can also be used within a standalone component. To do this:
- Export your component from the module:
@NgModule({
declarations: [MyFeatureComponent],
// export the NgModule-based component
exports: [MyFeatureComponent],
})
export class MyFeatureModule {
}
- 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.
@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.
@NgModule({
declarations: [
AppComponent,
StandaloneComponent
],
imports: [BrowserModule],
bootstrap: [AppComponent],
})
export class AppModule {}