Skip to content

Instantly share code, notes, and snippets.

@krishnaanaril
Created October 5, 2018 10:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save krishnaanaril/412001afccf2f74d1c840e1f7fb4b7fe to your computer and use it in GitHub Desktop.
Save krishnaanaril/412001afccf2f74d1c840e1f7fb4b7fe to your computer and use it in GitHub Desktop.
Method to embed Power BI report
embedPowerBIReport() {
this.service.getReportEmbedToken().subscribe((res) => {
let response = res.json();
let Token = response.EmbedToken;
const config = {
type: 'report',
tokenType: pbi.models.TokenType.Embed,
id: response.Id,
embedUrl: response.EmbedUrl,
accessToken: Token.token,
};
// Grab the reference to the div HTML element that will host the report.
const reportsContainer = <HTMLElement>document.getElementById(
'embedReport'
);
const report = this.powerbi.embed(
reportsContainer,
config
);
// Report.off removes a given event handler if it exists.
report.off('loaded');
// Report.on will add an event handler which prints to Log window.
report.on('loaded', (event)=>{
console.log('loaded: '+event);
this.setTokenExpirationListener(Token.expiration,
2 /*minutes before expiration*/);
})
report.off('pageChanged');
report.on('pageChanged', e => {
console.log(e);
});
report.on('error', function (event) {
console.log(event.detail);
report.off('error');
});
},
(error) => {
console.log(error);
})
}
@aghilimc
Copy link

Hi, Where is the project of this file? i can not find full surec of project

@krishnaanaril
Copy link
Author

@aghilimc Whole project is not available online. I've done this for an organization.

@jitinpurwal
Copy link

where this.powerbi defined? please let me know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment