v2.9 to v3.0 Angular UI Migration Guide

What Changed in v3.0?

Angular 10

The new ABP Angular UI is based on Angular 10 and TypeScript 3.9, and we have dropped support for Angular 8. Nevertheless, ABP modules will keep working with Angular 9. Therefore, if your project is Angular 9, you do not need to update to Angular 10. The update is usually very easy though.

What to Do When Migrating?

Open a terminal at your root folder and run the following command:

  1. yarn ng update @angular/cli @angular/core --force

This will make the following modifications:

  • Update your package.json and install new packages
  • Revise tsconfig.json files to create a “Solution Style” configuration
  • Rename browserslist as .browserslistrc

On the other hand, it would be better if you check which packages to update first with yarn ng update command alone. Angular will give you a list of packages to update.

Table of packages to update

When Angular reports the packages above, your command would look like this:

  1. yarn ng update @angular/cli @angular/core ng-zorro-antd --force

If Angular complains about uncommited changes in your repo, you can either commit/stash them or add --allow-dirty parameter to the command.

Config Modules

In ABP v2.x, every lazy loaded module had a config module available via a separate package and module configuration was as follows:

  1. import { AccountConfigModule } from '@abp/ng.account.config';
  2. @NgModule({
  3. imports: [
  4. // other imports
  5. AccountConfigModule.forRoot({ redirectUrl: '/' }),
  6. ],
  7. // providers, declarations, and bootstrap
  8. })
  9. export class AppModule {}

…and in app-routing.module.ts…

  1. const routes: Routes = [
  2. // other route configuration
  3. {
  4. path: 'account',
  5. loadChildren: () => import(
  6. './lazy-libs/account-wrapper.module'
  7. ).then(m => m.AccountWrapperModule),
  8. },
  9. ];

Although working, this had a few disadvantages:

  • Every module came in two independent packages, but in reality, those packages were interdependent.
  • Configuring lazy loaded modules required a wrapper module.
  • ABP Commercial had extensibility system and configuring extensible modules at the root module was increasing the bundle size.

In ABP v3.0, we have introduced a secondary entry points for each config module as well as a new way to configure lazy loaded modules without the wrappers. Now, the module configuration looks like this:

  1. import { AccountConfigModule } from '@abp/ng.account/config';
  2. @NgModule({
  3. imports: [
  4. // other imports
  5. AccountConfigModule.forRoot(),
  6. ],
  7. // providers, declarations, and bootstrap
  8. })
  9. export class AppModule {}

…and in app-routing.module.ts…

  1. const routes: Routes = [
  2. // other route configuration
  3. {
  4. path: 'account',
  5. loadChildren: () => import('@abp/ng.account')
  6. .then(m => m.AccountModule.forLazy({ redirectUrl: '/' })),
  7. },
  8. ];

This change helped us reduce bundle size and build times substantially. We believe you will notice the difference in your apps.

A Better Example

AppModule:

  1. import { AccountConfigModule } from '@abp/ng.account/config';
  2. import { CoreModule } from '@abp/ng.core';
  3. import { IdentityConfigModule } from '@abp/ng.identity/config';
  4. import { SettingManagementConfigModule } from '@abp/ng.setting-management/config';
  5. import { TenantManagementConfigModule } from '@abp/ng.tenant-management/config';
  6. import { ThemeBasicModule } from '@abp/ng.theme.basic';
  7. import { ThemeSharedModule } from '@abp/ng.theme.shared';
  8. import { NgModule } from '@angular/core';
  9. import { BrowserModule } from '@angular/platform-browser';
  10. import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
  11. import { NgxsModule } from '@ngxs/store';
  12. import { environment } from '../environments/environment';
  13. import { AppRoutingModule } from './app-routing.module';
  14. @NgModule({
  15. imports: [
  16. BrowserModule,
  17. BrowserAnimationsModule,
  18. AppRoutingModule,
  19. CoreModule.forRoot({
  20. environment,
  21. sendNullsAsQueryParam: false,
  22. skipGetAppConfiguration: false,
  23. }),
  24. ThemeSharedModule.forRoot(),
  25. AccountConfigModule.forRoot(),
  26. IdentityConfigModule.forRoot(),
  27. TenantManagementConfigModule.forRoot(),
  28. SettingManagementConfigModule.forRoot(),
  29. ThemeBasicModule.forRoot(),
  30. NgxsModule.forRoot(),
  31. ],
  32. // providers, declarations, and bootstrap
  33. })
  34. export class AppModule {}

AppRoutingModule:

  1. import { NgModule } from '@angular/core';
  2. import { RouterModule, Routes } from '@angular/router';
  3. const routes: Routes = [
  4. {
  5. path: '',
  6. pathMatch: 'full',
  7. loadChildren: () => import('./home/home.module').then(m => m.HomeModule),
  8. },
  9. {
  10. path: 'account',
  11. loadChildren: () =>
  12. import('@abp/ng.account').then(m => m.AccountModule.forLazy({ redirectUrl: '/' })),
  13. },
  14. {
  15. path: 'identity',
  16. loadChildren: () => import('@abp/ng.identity').then(m => m.IdentityModule.forLazy()),
  17. },
  18. {
  19. path: 'tenant-management',
  20. loadChildren: () =>
  21. import('@abp/ng.tenant-management').then(m => m.TenantManagementModule.forLazy()),
  22. },
  23. {
  24. path: 'setting-management',
  25. loadChildren: () =>
  26. import('@abp/ng.setting-management').then(m => m.SettingManagementModule.forLazy()),
  27. },
  28. ];
  29. @NgModule({
  30. imports: [RouterModule.forRoot(routes)],
  31. exports: [RouterModule],
  32. })
  33. export class AppRoutingModule {}

AppComponent:

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'app-root',
  4. template: `
  5. <abp-loader-bar></abp-loader-bar>
  6. <abp-dynamic-layout></abp-dynamic-layout>
  7. `,
  8. })
  9. export class AppComponent {}

You may have noticed that we used <abp-dynamic-layout> instead of <router-outlet> in the AppComponent template. We made this change in order to avoid unnecessary renders and flickering. It is not mandatory, but we recommend doing the same in your AppComponent.

What to Do When Migrating?

  • Remove config packages from your project using yarn remove.
  • Import config modules from secondary entry points (e.g. @abp/ng.identity/config).
  • Call static forRoot method of all new config modules, even if a configuration is not passed.
  • Call static forRoot method of ThemeBasicModule (or ThemeLeptonModule if commercial) and remove SharedModule from imports (unless you have added anything that is necessary for your root module in it).
  • Import lazy ABP modules directly in app routing module (e.g. () => import('@abp/ng.identity').then(...)).
  • Call static forLazy method of all lazy modules inside then, even if a configuration is not passed.
  • [OPTIONAL] Add the <abp-dynamic-layout></abp-dynamic-layout> to the AppComponent template and remove the <router-outlet></router-outlet> for better performance and UX.

RoutesService

In ABP v2.x, adding a route to the menu was done by one of two ways:

As of v3.0, we have changed how routes are added and modified. We are no longer storing routes in ConfigState (breaking change). Instead, there is a new service called RoutesService which is used for adding, patching, or removing menu items. Please check the documentation for details.

What to Do When Migrating?

  • Check if you have ever used ConfigState or ConfigStateService to add any routes. If so, replace them with add method of RoutesService.
  • Check if you have ever patched a route. If so, convert them to patch method of RoutesService.
  • Double-check that you are using absolute paths and providing a parentName instead of children property for sub-menu items in add or patch method calls.

NavItemsService

In ABP v2.x, adding a navigation element was done via LayoutStateService

As of v3.0, we have changed how navigation items are added and modified and previous method of doing so is no longer available (breaking change). Please check the documentation for details.

What to Do When Migrating?

  • Replace all dispatchAddNavigationElement calls with addItems method of NavItemsService.

ngx-datatable

Until v3, we had been using a custom component, abp-table, as the default table. However, data grids are complicated components and implementing a fully-featured one requires considerable effort, which we are planning to put in to other features and issues.

As of ABP v3, we have switched to a battle-tested, well-executed data grid: ngx-datatable. All ABP modules will come with ngx-datatable already implemented in them. ThemeSharedModule already exports NgxDatatableModule. So, if you install the package by running yarn add @swimlane/ngx-datatable in your terminal, it will be available for use in all modules of your app.

For proper styling, you need to add the following in the styles section of your angular.json file (above all others):

  1. "styles": [
  2. {
  3. "input": "node_modules/@swimlane/ngx-datatable/index.css",
  4. "inject": true,
  5. "bundleName": "ngx-datatable-index"
  6. },
  7. {
  8. "input": "node_modules/@swimlane/ngx-datatable/assets/icons.css",
  9. "inject": true,
  10. "bundleName": "ngx-datatable-icons"
  11. },
  12. {
  13. "input": "node_modules/@swimlane/ngx-datatable/themes/material.css",
  14. "inject": true,
  15. "bundleName": "ngx-datatable-material"
  16. },
  17. // other styles
  18. ]

Since abp-table is not dropped yet, modules previously built by ABP v2.x will not suddenly lose all their tables. Yet, they will look and feel different from built-in ABP v3 modules. Therefore, you will probably want to convert the tables in those modules to ngx-datatable. In order to decrease the amount of work required to convert an abp-table into ngx-datatable, we have modified the ListService to work well with ngx-datatable and introduced two new directives: NgxDatatableListDirective and NgxDatatableDefaultDirective.

The usage of those directives is rather simple:

  1. @Component({
  2. providers: [ListService],
  3. })
  4. export class SomeComponent {
  5. data$ = this.list.hookToQuery(
  6. query => this.dataService.get(query)
  7. );
  8. constructor(
  9. public readonly list: ListService,
  10. public readonly dataService: SomeDataService,
  11. ) {}
  12. }

…and in component template…

  1. <ngx-datatable
  2. [rows]="(data$ | async)?.items || []"
  3. [count]="(data$ | async)?.totalCount || 0"
  4. [list]="list"
  5. default
  6. >
  7. <!-- column templates here -->
  8. </ngx-datatable>

Once you bind the injected ListService instance through NgxDatatableListDirective, you no longer need to worry about pagination or sorting. Similarly, NgxDatatableDefaultDirective gets rid of several property bindings to make ngx-datatable fit our styles.

A Better Example

  1. <ngx-datatable
  2. [rows]="items"
  3. [count]="count"
  4. [list]="list"
  5. default
  6. >
  7. <!-- the grid actions column -->
  8. <ngx-datatable-column
  9. name=""
  10. [maxWidth]="150"
  11. [width]="150"
  12. [sortable]="false"
  13. >
  14. <ng-template
  15. ngx-datatable-cell-template
  16. let-row="row"
  17. let-i="rowIndex"
  18. >
  19. <abp-grid-actions
  20. [index]="i"
  21. [record]="row"
  22. text="AbpUi::Actions"
  23. ></abp-grid-actions>
  24. </ng-template>
  25. </ngx-datatable-column>
  26. <!-- a basic column -->
  27. <ngx-datatable-column
  28. prop="someProp"
  29. [name]="'::SomeProp' | abpLocalization"
  30. [width]="200"
  31. ></ngx-datatable-column>
  32. <!-- a column with a custom template -->
  33. <ngx-datatable-column
  34. prop="someOtherProp"
  35. [name]="'::SomeOtherProp' | abpLocalization"
  36. [width]="250"
  37. >
  38. <ng-template
  39. ngx-datatable-cell-template
  40. let-row="row"
  41. let-i="index"
  42. >
  43. <div abpEllipsis>{{ row.someOtherProp }}</div>
  44. </ng-template>
  45. </ngx-datatable-column>
  46. </ngx-datatable>

What to Do When Migrating?

  • Install @swimlane/ngx-datatable package.
  • Add ngx-datatable styles in the angular.json file.
  • If you can, update your modules according to the example above.
  • If you have to do that later and are planning to keep abp-table for a while, make sure you update your pagination according to the breaking change described here.

Important Note: The abp-table is not removed, but is deprecated and will be removed in the future. Please consider switching to ngx-datatable.

Extensions System [COMMERCIAL]

The extensions system is open sourced now and is publicly available from @abp/ng.theme.shared/extensions package instead of @volo/abp.commercial.ng.ui. Also, according to the new structure of config packages, the configuration is given through forLazy static methods as described above.

What to Do When Migrating?

If you have never used the extensions system before, you do not have to do anything. If you have, then please check the documentation again to see what changed. Extension system itself works the same as before. The only changes are the package you import from and the static method and the module you pass your contributors to.

Lepton Theme Logos [COMMERCIAL]

In ABP v2.x, Lepton had one light and one dark logo per color theme. We have realized we could make it work with only one light and one dark logo. So, we have changed how Lepton looks up logo images and now you just need to have a logo-light.png and a logo-dark.png in your project.

What to Do When Migrating?

If you have switched template logo PNGs before, the change is simple:

  • Go to /assets/images/logo folder.
  • Rename theme1.png as logo-light.png and theme1-reverse.png as logo-dark.png.
  • Delete all other theme*.png files.

If you have replaced the logo component(s), the change is a little bit different, but still simple. The LayoutStateService has a two new members: primaryLogoColor and secondaryLogoColor. They have an observable stream of 'light' and 'dark' strings as value. You can consume their value in your custom logo component templates with the async pipe. Here is a complete example which covers both primary and secondary (account) layout logos.

  1. import { AddReplaceableComponent } from '@abp/ng.core';
  2. import { CommonModule } from '@angular/common';
  3. import { APP_INITIALIZER, Component, Injector, NgModule } from '@angular/core';
  4. import { Store } from '@ngxs/store';
  5. import { eAccountComponents } from '@volo/abp.ng.account';
  6. import {
  7. AccountLayoutComponent,
  8. eThemeLeptonComponents,
  9. LayoutStateService,
  10. } from '@volo/abp.ng.theme.lepton';
  11. import { Observable } from 'rxjs';
  12. import { map } from 'rxjs/operators';
  13. @Component({
  14. template: `
  15. <div class="account-brand p-4 text-center mb-1" *ngIf="isAccount; else link">
  16. <ng-template [ngTemplateOutlet]="link"></ng-template>
  17. </div>
  18. <ng-template #link>
  19. <a [style.background-image]="logoUrl | async" class="navbar-brand" routerLink="/"></a>
  20. </ng-template>
  21. `,
  22. })
  23. export class LogoComponent {
  24. isAccount: boolean;
  25. logoColor: Observable<'dark' | 'light'>;
  26. get logoUrl() {
  27. return this.logoColor.pipe(map(color => `url(/assets/images/logo/logo-${color}.png)`));
  28. }
  29. constructor(injector: Injector) {
  30. const layout = injector.get(LayoutStateService);
  31. this.isAccount = Boolean(injector.get(AccountLayoutComponent, false));
  32. this.logoColor = this.isAccount ? layout.secondaryLogoColor : layout.primaryLogoColor;
  33. }
  34. }
  35. @NgModule({
  36. imports: [CommonModule],
  37. declarations: [LogoComponent],
  38. exports: [LogoComponent],
  39. })
  40. export class LogoModule {}
  41. export const APP_LOGO_PROVIDER = [
  42. { provide: APP_INITIALIZER, useFactory: switchLogos, multi: true, deps: [Store] },
  43. ];
  44. export function switchLogos(store: Store) {
  45. return () => {
  46. store.dispatch(
  47. new AddReplaceableComponent({
  48. component: LogoComponent,
  49. key: eThemeLeptonComponents.Logo,
  50. }),
  51. );
  52. store.dispatch(
  53. new AddReplaceableComponent({
  54. component: LogoComponent,
  55. key: eAccountComponents.Logo,
  56. }),
  57. );
  58. };
  59. }

Just add APP_LOGO_PROVIDER to the providers of your root module (usually AppModule) and you will have a custom logo component adjusting to the theme colors.

Deprecated Interfaces

Some interfaces have long been marked as deprecated and now they are removed.

What to Do When Migrating?

What’s Next?