This page explains how you can embed the Js Viewer component in your Angular application. To run the Angular Application Server, you will require the node.js JavaScript runtime and Angular CLI. Use the following command in the terminal or command prompt to install the Angular CLI:
npm install -g @angular/cli
Type a name for your project and click Next.
Select the Framework to a latest version and uncheck other options.
Add the following packages to the project.
MESCIUS.ActiveReports.Aspnetcore.Viewer
Create 'resources' folder in your sample project root; you can put your existing reports, themes, and images in this folder.
Make sure to set the Build Action property of the resources to 'Embedded Resource'.
Open 'Program.cs' file and update the file to include the 'using' statements at the top, and specify the resource folder and add services to container, so that the complete file looks like below.
Program.cs |
Copy Code
|
---|---|
using GrapeCity.ActiveReports.Aspnetcore.Viewer; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddReportViewer(); builder.Services.AddControllers(); var app = builder.Build(); var ResourcesRootDirectory = new DirectoryInfo(Path.Combine(Directory.GetCurrentDirectory(), "resources")); app.UseRouting(); app.UseDefaultFiles(); app.UseStaticFiles(); app.UseRouting(); app.UseReportViewer(config => config.UseFileStore(ResourcesRootDirectory)); // Configure the HTTP request pipeline. app.UseHttpsRedirection(); app.UseAuthorization(); app.MapControllers(); app.MapFallbackToFile("/index.html"); app.Run(); |
In the '.client' project, open 'package.json' file and add the following packages under 'dependencies':
"@mescius/activereportsnet-viewer": "^18.x.x"
npm install
The viewer files/folders will be downloaded in your current directory: .\node_modules\@mescius\activereportsnet-viewer\dist.app.component.ts |
Copy Code
|
---|---|
import { Component, OnInit } from '@angular/core'; import { createViewer } from '@mescius/activereportsnet-viewer'; import '@mescius/activereportsnet-viewer/dist/jsViewer.min.css'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrl: './app.component.css' }) export class AppComponent implements OnInit { title = "app"; ngOnInit() { this.viewer = createViewer({ element: '#viewer-host' }); this.viewer.openReport("DemoReport.rdlx"); } } |
Open the 'app.component.html' file and replace the existing content with the following markup for hosting the element.
app.component.html |
Copy Code
|
---|---|
<body>
<div id="viewer-host"></div>
</body>
|
styles.css |
Copy Code
|
---|---|
#viewer-host { width: 100%; height: 100vh; } |
Open 'proxy.conf.js' file and update the 'context' section of code as follows.
proxy.conf.js |
Copy Code
|
---|---|
context: [ "/weatherforecast", "/api" ], |
Press Ctrl + Shift + B to build your application and then press F5 to run it.
On running the application, you can find the report placed in the resource folder by navigating to File menu > Open.