ramandeep-singh-1983 / ngx-powerbi

TypeScript library for embedding Power BI assets (reports/dashboards/tiles) in your application. This TypeScript library is built on top of the official powerbi-client library provided by Microsoft.
MIT License
36 stars 22 forks source link

Property 'getPages' does not exist on type 'Embed' #12

Closed celvin closed 5 years ago

celvin commented 5 years ago

I'm using your nice wrapper library with Angular 7, and it is almost fully working, I am getting just some typescript compiling errors like this:

error TS2339: Property 'getPages' does not exist on type 'Embed'.

        report.on('loaded', function(event): any {
            report.getPages().then(function(pages) {
                console.log('report loaded, number of pages: ', pages.length);
                // We only want to handle the 'loaded' event once
                report.off('loaded');
            });
        });
ramandeep-singh-1983 commented 5 years ago

Hi there,

Thanks for using the library. About the error, it seems that the 'report' object is of type 'Embed' whereas it should be of type 'Report' as the 'getPages' API is part of the 'Report' class. You can simply typecast it to 'Report' type or try the code below:

import { Report } from 'report'; // This is part of powerbi-client library so you will need to install the same

embedReport() {
    const report: Report = <Report>(this.powerBiService.embed(this.pbiContainerElement, config));

    // Now all 'report' object APIs should work
    report.on('loaded', function(event): any {
            report.getPages().then(function(pages) {
                console.log('report loaded, number of pages: ', pages.length);
                // We only want to handle the 'loaded' event once
                report.off('loaded');
            });
        });
}
celvin commented 5 years ago

Thanks, It worked very well, thanks.

now just a small lint on then(function(pages) .... expected call-signature to have a typedeftslint(typedef)

I have changed it to:

            report.getPages().then(pages => {
                console.log('report loaded, number of pages: ', pages.length);
                report.off('loaded');
            });

this issue can be considered as closed, thank you!

lucaspein commented 4 years ago

Not working for me.