Angular wrapper for powerbi-client library
npm install powerbi-client-angularts
import { PowerBIEmbedModule } from 'powerbi-client-angular';
@NgModule({
imports: [
...
...
PowerBIEmbedModule
],
exports: ...,
declarations: ...
})
`
$3
`ts
[embedConfig] = {{
type: "report",
id: "",
embedUrl: " `
$3
`ts
[embedConfig] = {{
type: "report",
id: undefined,
embedUrl: undefined,
accessToken: undefined, // Keep as empty string, null or undefined
tokenType: models.TokenType.Embed,
hostname: "https://app.powerbi.com"
}}
>
`
__Note__: To embed the report after bootstrapping, update the embedConfig (with at least accessToken and embedUrl).
Embedding other Power BI artifacts
The library is offering the following components that can be used to embed various Power BI artifacts.
|Component|Selector to use for embedding|
|:------|:------|
|PowerBIReportEmbedComponent|``|
|PowerBIDashboardEmbedComponent|``|
|PowerBITileEmbedComponent|``|
|PowerBIVisualEmbedComponent|``|
|PowerBIQnaEmbedComponent|``|
|PowerBIPaginatedReportEmbedComponent|``|
|PowerBICreateReportEmbedComponent|`powerbi-create-report`|
You can embed other artifacts such as:
`ts
[embedConfig] = ""
[cssClassName] = ""
[eventHandlers] = " `
$3
This demo includes an Angular application that embeds a sample report using the _PowerBIReportEmbed_ component.
It demonstrates the complete flow from bootstrapping the report, to embedding and updating the embedded report.
It also demonstrates using the powerbi report authoring library, by enabling the user to change the type of a report visual from a report using the "Change visual type" button.
It also sets a 'DataSelected' event.
To run the demo on localhost, run the following command:
`
npm run demo
`
Redirect to http://localhost:4200/ to view in the browser.
$3
|Use case|Details|
|:------|:------|
|Embed Power BI|To embed your powerbi artifact, pass the component with at least type, embedUrl and accessToken in embedConfig property.|
|Apply style class|Pass the name(s) of style classes to be applied to the embed container div to the cssClassName property.|
|Set event handlers|Pass a map object of event name (string) and event handler (function) to the _eventHandlers_ prop.
__Key__: Event name
__Value__: Event handler method to be triggered
Event handler method takes two optional parameters:
First parameter: Event
Second parameter: Reference to the embedded entity
List of supported events is given here: Additional events|
|Reset event handlers|To reset event handler for an event, set the event handler's value as null in the eventHandlers map of properties.|
|Bootstrap Power BI|To bootstrap your powerbi entity, pass the property embedConfig to the component without _accessToken_
__Note__: _embedConfig_ should at least contain __type__ of the powerbi entity being embedded.
Available types: "report", "dashboard", "tile", "visual" and "qna".
Refer to _How to bootstrap a report_ section in Quick Start.
__Note__: A paginated report cannot be bootstrapped.|
|Using with PowerBI Report Authoring|1. Install powerbi-report-authoring as an npm dependency.
2. Use the report authoring APIs using the embedded report's instance.|
|Phased embedding (Report type only)|Set the phasedEmbedding property value to true
Refer to the Phased embedding article.|
|Create report|To create a new report, pass the component with at least _type_, _embedUrl_ and _datasetId_ in _embedConfig_ prop.|
__Note__: Supported browsers are _Edge_, _Chrome_, and _Firefox_.
$3
|Property|Description|Supported by|
|:-------|:----------|:----------|
|embedConfig|Configuration for embedding the PowerBI entity (required)|All|
|phasedEmbedding|Phased embedding flag (optional)|Report|
|eventHandlers|Map of pair of event name and its handler method to be triggered on the event (optional)|Report, Dashboard, Tile, Visual, Qna|
|cssClassName|CSS class to be set on the embedding container (optional)|All|
|service|Provide the instance of PowerBI service (optional)|All|
Supported Events
$3
|Entity|Event|
|:----- |:----- |
| Report | "buttonClicked", "commandTriggered", "dataHyperlinkClicked", "dataSelected", "loaded", "pageChanged", "rendered", "saveAsTriggered", "saved", "selectionChanged", "visualClicked", "visualRendered" |
| Dashboard | "loaded", "tileClicked" |
| Tile | "tileLoaded", "tileClicked" |
| QnA | "visualRendered" |
$3
`ts
type EventHandler = (event?: service.ICustomEvent, embeddedEntity?: Embed) => void | null;
`
Using supported SDK methods for Power BI artifacts
$3
Import the 'PowerBIReportEmbedComponent' inside your targeted component file:
`ts
import { PowerBIReportEmbedComponent } from 'powerbi-client-angular';
`
$3
`ts
@ViewChild(PowerBIReportEmbedComponent) reportObj!: PowerBIReportEmbedComponent;
`
$3
You can use `reportObj` to call supported SDK APIs.
There are two ways in which `reportObj` can be used:
* Expose the `Report` object globally.
Steps:
1. Create one class variable, for example, `report`.
2. Implement the ` AfterViewInit ` hook for the component class.
`ts
class AppComponent implements AfterViewInit { ... }
`
3. Define the `ngAfterViewInit` method as follows:
`ts
ngAfterViewInit(): void {
this.report = this.reportObj.getReport();
}
`
4. this.report points to the Report object from the library and can be used to call SDK methods such as, `getVisuals`, `getBookmarks` etc.
`ts
async getReportPages(): Page[] {
// this.report is a class variable, initialized in step 3
const pages = await this.report.getPages();
console.log(pages);
}
`
* Use `reportObj` inside a class method.
This approach will not expose the Report object globally, instead `reportObj` would be available locally in the function.
Example:
`ts
async getReportPages(): Page[] {
const report = this.reportObj.getReport();
const visuals = await report.getPages();
console.log(visuals);
}
``