1- import { Component , OnInit } from '@angular/core' ;
1+ import { AfterViewInit , Component , Inject , OnInit , PLATFORM_ID } from '@angular/core' ;
22import { AuthService } from '../core/auth/auth.service' ;
33import { take } from 'rxjs/operators' ;
44import { EPerson } from '../core/eperson/models/eperson.model' ;
55import { ScriptLoaderService } from './script-loader-service' ;
66import { HALEndpointService } from '../core/shared/hal-endpoint.service' ;
77import { LocaleService } from '../core/locale/locale.service' ;
8+ import { isPlatformBrowser } from '@angular/common' ;
89
910/**
1011 * The component which wraps `language` and `login`/`logout + profile` operations in the top navbar.
@@ -14,12 +15,13 @@ import { LocaleService } from '../core/locale/locale.service';
1415 templateUrl : './clarin-navbar-top.component.html' ,
1516 styleUrls : [ './clarin-navbar-top.component.scss' ]
1617} )
17- export class ClarinNavbarTopComponent implements OnInit {
18+ export class ClarinNavbarTopComponent implements OnInit , AfterViewInit {
1819
1920 constructor ( private authService : AuthService ,
2021 private halService : HALEndpointService ,
2122 private scriptLoader : ScriptLoaderService ,
22- private localeService : LocaleService ) { }
23+ private localeService : LocaleService ,
24+ @Inject ( PLATFORM_ID ) private platformId : Object ) { }
2325
2426 /**
2527 * The current authenticated user. It is null if the user is not authenticated.
@@ -47,7 +49,16 @@ export class ClarinNavbarTopComponent implements OnInit {
4749 } else {
4850 this . authenticatedUser = null ;
4951 }
52+ }
53+
54+ ngAfterViewInit ( ) : void {
55+ // Load scripts only in the browser and not SSR
56+ if ( isPlatformBrowser ( this . platformId ) ) {
57+ this . loadScripts ( ) ;
58+ }
59+ }
5060
61+ loadScripts ( ) {
5162 // At first load DiscoJuice, second AAI and at last AAIConfig
5263 this . loadDiscoJuice ( ) . then ( ( ) => {
5364 this . loadAAI ( ) . then ( ( ) => {
0 commit comments