Hello, I'm new to integrating GoodData with Angula...
# gd-beginners
s
Hello, I'm new to integrating GoodData with Angular, and I’m using GoodData web components in my application. I need to dynamically display a
gd-dashboard
based on the workspace ID received from an API response. The workspace ID is required in the GoodData script, which I would typically add to the
<head></head>
section of the HTML. However, Angular treats dynamically adding scripts as a security issue and prevents this from being done. Is there a way to load the GoodData script dynamically in Angular without violating Angular's security restrictions? Or, is there another approach to loading the GoodData web component in this scenario? Any help would be greatly appreciated. Thank you!
👍 1
j
Hi @Shahenshah Malik, I believe the solution here is about making the URL as trusted with
DomSanitizer
library. There is a thread on StackOverflow, that nicely describes how to mark that URL as safe: • bypassSecurityTrustResourceUrl should be generally avoided as it may expose application to security risks • sanitize is then the function that will create a safe and trusted value, you should be able to dynamically import. I hope it helps.
s
Thanks so much, let me try that
The stackoverflow solution worked and I'm able to load the dashboard, I have another problem though below is the code I'm trying in Angular, I'm able to see the dashboard id on screen but still get this error in console
Copy code
@if(dashboardId) {
    {{dashboardId}}
    <gd-dashboard class="dashboard" dashboard="{{dashboardId}}" #dashboard></gd-dashboard>
}
@else {
    <div class="error">No dashboard ID provided</div>
}
I tried both, property binding as well as interpolation, nothing seems to work
but when I provide hard coded id it loads
I resolved it by injecting the gd-dashboard element dynamically
Copy code
const gdElement = document.createElement('gd-dashboard');
			gdElement.classList.add('dashboard');
			gdElement.setAttribute('dashboard', this.dashboardId);
			
			document.getElementById('dashboardContainer').appendChild(gdElement);
🙌 1