@@ -14,9 +14,9 @@ import { Metric } from '../../../core/shared/metric.model';
1414import { BaseMetricComponent } from './base-metric.component' ;
1515import { MetricLoaderService } from './metric-loader.service' ;
1616import { hasValue } from '../../empty.util' ;
17- import { BrowserKlaroService , CookieConsents } from '../../cookies/browser-klaro.service' ;
17+ import { CookieConsents } from '../../cookies/browser-klaro.service' ;
1818import { KlaroService } from '../../cookies/klaro.service' ;
19- import { startWith } from 'rxjs/operators' ;
19+ import { startWith } from 'rxjs/operators' ;
2020
2121@Component ( {
2222 // eslint-disable-next-line @angular-eslint/component-selector
@@ -50,22 +50,19 @@ export class MetricLoaderComponent implements OnInit, OnDestroy {
5050
5151 private thirdPartyMetrics = [ 'plumX' , 'altmetric' , 'dimensions' ] ;
5252
53- private browserKlaroService : BrowserKlaroService ;
54-
5553 private hasLoadedScript : boolean ;
5654
5755 constructor (
5856 private componentFactoryResolver : ComponentFactoryResolver ,
5957 private metricLoaderService : MetricLoaderService ,
6058 private klaroService : KlaroService ,
6159 ) {
62- this . browserKlaroService = ( this . klaroService as BrowserKlaroService ) ;
63- this . browserKlaroService . watchConsentUpdates ( ) ;
64- this . consentUpdates$ = this . browserKlaroService . consentsUpdates$ ;
60+ this . klaroService . watchConsentUpdates ( ) ;
61+ this . consentUpdates$ = this . klaroService . consentsUpdates$ ;
6562 }
6663
6764 ngOnInit ( ) {
68- this . cookiesSubscription = this . browserKlaroService . getSavedPreferences ( ) . subscribe ( ( consents ) => {
65+ this . cookiesSubscription = this . klaroService . getSavedPreferences ( ) . subscribe ( ( consents ) => {
6966 this . loadComponent ( this . metric , this . getCanLoadScript ( consents ) ) ;
7067 } ) ;
7168 }
@@ -96,6 +93,8 @@ export class MetricLoaderComponent implements OnInit, OnDestroy {
9693 instantiateComponent ( component : any , metric : Metric , canLoadScript : boolean , forceRendering ?: boolean ) {
9794 const factory = this . componentFactoryResolver . resolveComponentFactory ( component ) ;
9895 this . componentType = component ;
96+ this . container . clear ( ) ;
97+
9998 const ref = this . container . createComponent ( factory ) ;
10099 const componentInstance = ref . instance as BaseMetricComponent ;
101100 componentInstance . metric = metric ;
@@ -133,14 +132,18 @@ export class MetricLoaderComponent implements OnInit, OnDestroy {
133132 * @private
134133 */
135134 private reloadComponentOnConsentsChange ( componentInstance : BaseMetricComponent , canLoadScript : boolean ) : void {
135+ if ( hasValue ( this . settingsSubscription ) ) {
136+ return ;
137+ }
138+
136139 this . settingsSubscription = combineLatest ( [
137140 this . consentUpdates$ ,
138141 componentInstance . requestSettingsConsent . pipe ( startWith ( undefined ) )
139142 ] ) . subscribe ( ( [ consents , request ] ) => {
140143 canLoadScript = this . getCanLoadScript ( consents ) ;
141144
142145 if ( request && ! canLoadScript ) {
143- this . browserKlaroService . showSettings ( ) ;
146+ this . klaroService . showSettings ( ) ;
144147 }
145148
146149 if ( canLoadScript && ! this . hasLoadedScript ) {
0 commit comments