forked from DSpace/dspace-angular
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The Autocomplete Component is dynamically loaded as a standalone comp…
…onent only in the browser using the Loader component. (#763)
- Loading branch information
1 parent
50f68bb
commit d3aa70d
Showing
5 changed files
with
61 additions
and
35 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
src/app/login-page/autoregistration/autoregistration-loader.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Component, Inject, OnInit, PLATFORM_ID, ViewChild, ViewContainerRef, ComponentFactoryResolver } from '@angular/core'; | ||
import { isPlatformBrowser } from '@angular/common'; | ||
|
||
/** | ||
* Component that dynamically loads the AutoregistrationComponent only in the browser | ||
*/ | ||
@Component({ | ||
selector: 'ds-autoregistration-loader', | ||
template: '<ng-template #dynamicComponent></ng-template>', | ||
}) | ||
export class AutoregistrationLoaderComponent implements OnInit { | ||
@ViewChild('dynamicComponent', { read: ViewContainerRef }) dynamicComponent: ViewContainerRef; | ||
|
||
isBrowser: boolean; | ||
|
||
constructor( | ||
@Inject(PLATFORM_ID) private platformId: object, | ||
private componentFactoryResolver: ComponentFactoryResolver | ||
) { | ||
this.isBrowser = isPlatformBrowser(this.platformId); // Check if running in the browser | ||
} | ||
|
||
ngOnInit(): void { | ||
if (this.isBrowser) { | ||
// Dynamically load the AutoregistrationComponent only in the browser | ||
import('./autoregistration.component').then(({ AutoregistrationComponent }) => { | ||
const componentFactory = | ||
this.componentFactoryResolver.resolveComponentFactory(AutoregistrationComponent); | ||
const componentRef = this.dynamicComponent.createComponent(componentFactory); | ||
componentRef.changeDetectorRef.detectChanges(); | ||
}); | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/app/login-page/autoregistration/autoregistration.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters