Category: Angular

Announcing Power BI Angular Component

Microsoft has announced a new component library for the Power BI which will work with the Angular Framework.

The Angular component is now live and available on npm and GitHub.

Check out the sample code below to see how to get started embedding Power BI in your Angular application.

IMPORTING THE LIBRARY

import { PowerBIEmbedModule } from 'powerbi-client-angular';
@NgModule({imports: [ PowerBIEmbedModule]})

EMBEDDING A POWER BI REPORT IN AN ANGULAR APPLICATION:

<powerbi-report
    [embedConfig] = {
        {
            type: "report",
            id: "<Report Id>",
            embedUrl: "<Embed Url>",
            accessToken: "<Access Token>",
            tokenType: models.TokenType.Embed,
                settings: {...},
        }
    }
    [cssClassName] = { "reportClass" }
    [phasedEmbedding] = { false }
    [eventHandlers] = {
        new Map([
            ['loaded', () => console.log('Report loaded');],
        ])
    }
></powerbi-report>

The full code and instructions can be found in the Power BI Angular README.

If you want a glance at the look and feel of the new component, you can check out our demo application here.

The app demonstrates the complete flow from bootstrapping the report, to embedding and updating the embedded report, as well as setting events and enabling report authoring.

You can find instructions on how to run the demo in the demo section of the Power BI Angular README.

That’s all for this post. We hope you found it useful.

We’d love to hear more from you! Have any feedback or a great new feature in mind? Please share it with us or vote in our Power BI Embedded Analytics Ideas forum.

Reference Link: https://powerbi.microsoft.com/en-us/blog/announcing-power-bi-angular-component/

DEMO Link: https://powerbi.microsoft.com/en-us/blog/announcing-power-bi-angular-component

ANGULAR – Unsafe values used in a resource URL Context

Ok, when you get this error you are probably trying to use url variable in you template. The most elegant way to fix this is use pipe to bypass security. In this example we will pass URL variable into iframe src.

First of all we will create our pipe. We are injecting the DomSanitizer service, SecurityContext and executing the sanitize and bypassSecurityTrustResourceUrl method to sanitize and bypass security to trust the given value to be a safe style URL.

Note: calling these methods with untrusted USER DATA exposes your application to XSS security risks!

 
import { Pipe, PipeTransform } from '@angular/core';

import { DomSanitizer } from '@angular/platform-browser';
@Pipe({
name: 'safe'
})
export class SafePipe implements PipeTransform {
constructor(private sanitizer: DomSanitizer) { }
transform(url) {
return this.sanitizer.bypassSecurityTrustResourceUrl(url);
}
}

Now add you pipe to app.module:

@NgModule({
imports: [ BrowserModule ],
declarations: [ App, SafePipe ],
bootstrap: [ App ]
})


Then just use it!
<iframe [src]="url | safe"></iframe>

You can create pipes or implement logic for other contexts:

SecurityContext.NONE
SecurityContext.HTML
SecurityContext.STYLE
SecurityContext.SCRIPT
SecurityContext.URL
SecurityContext.RESOURCE_URL


courtesy:
https://filipmolcik.com/error-unsafe-value-used-in-a-resource-url-context/

© 2023

Theme by Anders NorenUp ↑