Skip to content

Commit

Permalink
feat: data-style attributes added for mfe wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
markuczy committed Feb 28, 2025
1 parent 8eda746 commit 348bc12
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@ import { AppStateService } from '@onecx/angular-integration-interface'
import { firstValueFrom } from 'rxjs'

@Component({
template: '<div #wrapper></div>'
template: '<div #wrapper [attr.data-style-id]="styleId" data-style-isolation></div>'
})
export class WebcomponentLoaderComponent implements AfterContentInit {
@ViewChild('wrapper', { read: ElementRef, static: true })
wrapper?: ElementRef

styleId = ''

constructor(private readonly appStateService: AppStateService) {}

async ngAfterContentInit() {
const currentMfe = await firstValueFrom(this.appStateService.currentMfe$.asObservable())

if (!currentMfe.elementName) throw new Error('elementName is missing in the configuration')

this.styleId = `${currentMfe.productName}|${currentMfe.appId}`

const element = document.createElement(currentMfe.elementName)
this.wrapper?.nativeElement.appendChild(element)
}
Expand Down

0 comments on commit 348bc12

Please sign in to comment.