How to use the Native Angular Report Viewer with Report Server for .NET
The article explains how to set up the Native Angular Report Viewer to work with the Telerik Report Server for .NET.
The user account that will authenticate with the Report Server may be any User, including the Guest User, provided there is an enabled Token in its Tokens collection.
Prerequisites
- Review the Native Angular Report Viewer Requirements.
- Installed and running Telerik Report Server for .NET.
- Report Server for .NET's User that will connect from the viewer should have at least one enabled Token.
- Report Server for .NET should contain at least one report that can be accessed by the User account.
Steps
-
Install the Native Angular Report Viewer NPM package with the following command:
npm install @progress/telerik-angular-native-report-viewerIf you receive a 403 Forbidden Error, you need to register and log in at npmjs.com before performing this step.
npm login --registry=https://registry.npmjs.org --scope=@progress -
Once installed, import the
ReportingAngularViewerModulein your application root module:import { ReportingAngularViewerModule } from '@progress/telerik-angular-native-report-viewer'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, BrowserAnimationsModule, AppRoutingModule, ReportingAngularViewerModule ], providers: [], bootstrap: [AppComponent] }) -
Install the Angular
localizepackage - Add the localize packageng add @angular/localize -
Install one of the Kendo UI for Angular themes, e.g. the Default Theme
npm install --save @progress/kendo-theme-default -
Reference the theme in the project using one of the supported approaches - Compiling Themes from SCSS Source Files. In this example, we will use the approach with the
angular.jsonconfiguration, which consists of adding the desired theme inside thestylesarray - Angular workspace configuration: Styles and scripts configuration:"styles": [ "src/styles.scss", "node_modules/@progress/kendo-theme-default/dist/default-ocean-blue.scss" ], -
In the class of the component(e.g.
AppComponent) where the viewer will be displayed, define areportSourceobject property specifying the category and the name of the report that will be displayed. For example, if the category is Samples and the report is Dashboard, the syntax will look as follows:reportSource = { report: 'Samples/Dashboard', parameters: {} } -
In the same component class, define a
reportServerobject property with aurlstring pointing to the Report Server for .NET, and agetPersonalAccessTokencallback, which will be executed when the report viewer requests from the server to render the report.reportServer = { url: 'http://dnikolovlap:81/', getPersonalAccessToken: () => fetch('/rs-token').then(response => response.text()) }In this example, the
getPersonalAccessTokencallback makes a request to a /rs-token endpoint that returns the token used to authorize access to using the Report Server for .NET REST API.This is the recommended approach, but if an endpoint cannot be exposed, the token can be hardcoded in the callback:
getPersonalAccessToken: () => Promise.resolve('TOKEN_STRING') -
In the HTML template of the component, define the
<reporting-angular-viewer>element, and pass the defined properties to their corresponding properties of the Native Angular Report Viewer:<reporting-angular-viewer serviceType="reportServer" [reportServer]="reportServer" [reportSource]="reportSource"> </reporting-angular-viewer> -
Run the application:
ng serve