Add Web Report Designer to an Angular application using Angular CLI
To add the Bold Reports® Web Report Designer to an Angular application that uses an Angular CLI version earlier than 17, install the Bold Reports® Angular package, add the script and style references, and set the Web API service URL.
If you are using a higher version of Angular CLI (>= v17.x), then refer to Add Report Designer to an Angular application.
What do I need before adding the Report Designer to an Angular app?
To add the Bold Reports® Angular Report Designer with an Angular CLI version earlier than 17, your development environment needs Node JS and NPM at the versions listed below.
Before getting started with the Bold Reports® Report Designer, make sure your development environment includes the following:
- Node JS (
version 8.x or 10.x) Version Compatibility. - NPM (v3.x.x or higher)
Install the Angular CLI
To install the Angular CLI globally on your machine for the Report Designer application, run the following command in Command Prompt. The Angular CLI provides the easiest way to set up Angular projects.
npm install -g @angular/cliTo learn more about Angular CLI commands, see the Angular CLI repository on GitHub.
Create a new application
To create a new Angular application, run the following command in Command Prompt.
```typescript
ng new project-name
E.g : ng new reportdesignerapp
```The
ng newcommand prompts you for information about features to include in the initial application project. Add theAngular Routingto your angular application by enteringyin the prompt window then press Enter key. Now, choose theCSSstylesheet format using the arrow keys and then press Enter key. The Angular CLI installs the required Angular npm packages and other dependencies.
Configure Bold Reports® Report Designer in Angular CLI
The Bold Reporting packages are distributed in npm as @boldreports/angular-reporting-components.
-
To configure the web Report Designer component, change the directory to your application’s root folder.
cd project-name E.g : cd reportdesignerapp -
Run the following commands to install the Bold Reports® Angular library.
Angular version NPM package installation 12 or greater than 12 npm install @boldreports/angular-reporting-components@latest —save-dev lesser than 12 npm install @boldreports/[email protected] —save-dev Note: It is important to exercise caution during the package installation process to avoid potential complications with package compilation.
-
Install the
typingsdependenciesreports.all,jquery,types/jqueryandjsrenderusing the following commands.npm install @boldreports/types npm install --save-dev jquery npm install --save-dev @types/jquery npm install --save-dev @types/jsrender -
Add the typings
jquery,jsrender, andreports.allto thetsconfig.app.jsonfile.{ ... ... "compilerOptions": { ... ... "baseUrl": "", "types": [ "jquery", "jsrender", "reports.all" ] }, ... ... } -
Register the
@bold-reports/typesunder thetypeRootsnode in thetsconfig.jsonfile.
-
The Report Viewer requires a
window.jQueryobject to render the component.-
For
Angular version 12 or higher, Refer the jQuery script file (jquery.js) as given in theangular.jsonfile within theprojectname > scriptssection (For example,reportdesignerapp > scripts).{ "$schema": "./node_modules/@angular/cli/lib/config/schema.json", "projects": { "reportdesignerapp": { "root": "src", "outDir": "dist", . . . . . . "styles": [ "src/styles.css" ], "scripts": [ "./node_modules/jquery/dist/jquery.js" ], . . . . . . } } } -
For
Angular version lesser than 12, importjQueryinto thesrc/polyfills.tsfile as shown in the following code snippet:import * as jquery from 'jquery'; let windowInstance = (window as { [key: string]: any }); windowInstance['jQuery'] = jquery; windowInstance['$'] = jquery;
-
Adding CSS reference
-
Open the
angular.jsonfile from your application’s root directory. -
Add the Report Designer component style (
bold.report-designer.min.css) as given in theangular.jsonfile within theprojectname > stylessection (For example,reportdesignerapp > styles).{ "$schema": "./node_modules/@angular/cli/lib/config/schema.json", "projects": { "reportdesignerapp": { "root": "src", "outDir": "dist", . . . . . . "styles": [ "src/styles.css", "./node_modules/@boldreports/javascript-reporting-controls/Content/v2.0/tailwind-light/bold.report-designer.min.css" ], "scripts": [], . . . . . . } } }In the preceding code snippet, the
materialtheme is used. You can modify the theme based on your application, refer the following syntax:./node_modules/@boldreports/javascript-reporting-controls/Content/[theme-name]/bold.reports.all.min.css.
Adding code mirror reference
The Bold Reports® Report Designer requires the code mirror scripts and styles to edit the SQL queries and Visual Basic code functions with a syntax highlighter.
-
Run the following command to install the code mirror dependencies.
npm install codemirror@5.45.0 -
Open the
angular.jsonfile from your application’s root directory and reference the code mirror scripts and styles under thescriptsandstylesnodes of theprojectssection, as in the following code example:If you are using Angular 6 or lower version project, add the changes in
angular-cli.jsonfile.{ "$schema": "./node_modules/@angular/cli/lib/config/schema.json", "projects": { "reportdesignerapp": { "root": "src", "outDir": "dist", . . . . . . "styles": [ "src/styles.css", "./node_modules/codemirror/lib/codemirror.css", "./node_modules/codemirror/addon/hint/show-hint.css" ], "scripts": [ "./node_modules/codemirror/lib/codemirror.js", "./node_modules/codemirror/addon/hint/show-hint.js", "./node_modules/codemirror/addon/hint/sql-hint.js", "./node_modules/codemirror/mode/sql/sql.js", "./node_modules/codemirror/mode/vb/vb.js", "./node_modules/jquery/dist/jquery.js" ], . . . . . . } } }
Adding Report Designer component
To add the Bold Reports® Report Designer component, use the following steps:
-
Open the
src/app/app.module.tsfile. -
You can replace the following code snippet in the
app.module.tsfile.import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { BoldReportDesignerModule } from '@boldreports/angular-reporting-components'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; //Report Designer component dependent scripts import '@boldreports/javascript-reporting-controls/Scripts/v2.0/common/bold.reports.common.min.js'; import '@boldreports/javascript-reporting-controls/Scripts/v2.0/common/bold.reports.widgets.min.js'; //Report Viewer and Designer component scripts import '@boldreports/javascript-reporting-controls/Scripts/v2.0/bold.report-viewer.min.js'; import '@boldreports/javascript-reporting-controls/Scripts/v2.0/bold.report-designer.min.js'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, BoldReportDesignerModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }If you are using Angular CLI version 10.x.x, you will get a warning like
CommonJS or AMD dependencies can cause optimization bailouts. To resolve this warning, you need to register the Bold Reports® JavaScript files underallowedCommonJsDependenciesarray inangular.jsonfile.. . . "build": { "builder": "@angular-devkit/build-angular:browser", "options": { "allowedCommonJsDependencies": [ "@boldreports/javascript-reporting-controls/Scripts/bold.report-viewer.min", "@boldreports/javascript-reporting-controls/Scripts/bold.report-designer.min" ], . . . . . . -
Open the
src/app/app.component.htmlfile and initialize the web Report Designer. -
You can replace the following code snippet in the
app.component.htmlfile.<bold-reportdesigner id="designer" style="position: absolute;height: 550px; width: 1250px;"> </bold-reportdesigner> -
Open the
src/app/app.component.tsfile and replace its content with the following code example:import { Component } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { title = 'reportdesignerapp'; public serviceUrl: string; constructor() { // Initialize the Report Designer properties here. } }If you get the issue
'ej' is not definedafter the previous configuration in Angular CLI version 7, add the following code snippet to the file where you render the Bold Reporting Components (model file) to resolve the issue.`/// <reference types="reports.all" />`
Create Web API service
The Bold Reports® Report Designer requires a Web API service to process the data and file actions. You can skip this step and use the online Web API service at https://demos.boldreports.com/services/api/ReportingAPI to create, edit, and browse reports. Otherwise, create one of the following Web API services.
Set Web API service URL
To set the Web API service URL for the Report Designer, open the app.component.ts file and add the following code snippet in the constructor.
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'reportdesignerapp';
public serviceUrl: string;
constructor() {
this.serviceUrl = "https://demos.boldreports.com/services/api/ReportingAPI";
}
}Open the app.component.html to set the ServiceUrl property of the Report Designer as in the following code snippet:
<bold-reportdesigner id="designer" [serviceUrl] = "serviceUrl" style="position: absolute;height: 550px; width: 1250px;">
</bold-reportdesigner>Serve the application
To serve the Report Designer application, run the ng serve command from the workspace folder.
-
Go to the workspace folder (reportdesignerapp).
-
Launch the server by using the CLI command ng serve, with the —open option.
ng serve --open -
The
ng servecommand launches the server and the--openoption automatically opens your browser tohttp://localhost:4200/.