Closed yanmariomenev closed 2 months ago
The error seems to be caused by an incorrect application set up - document
is referenced in the app.component.ts
providers. Removing it and setting the appendTo
option of the NotificationSettings resolves the issue.
In app.component.ts
:
@ViewChild("container", { read: ViewContainerRef })
public container: ViewContainerRef | any;
constructor(private notificationService: NotificationService) {}
ngAfterViewInit(){
this.displayNotification()
}
public displayNotification(): void {
this.notificationService.show({
content: "Custom Notification",
appendTo: this.container,
position: { horizontal: "center", vertical: "bottom" },
type: { style: "info", icon: true },
});
}
In app.component.html
:
<div class="append-container" #container></div>
Describe the bug If the NotificationService is used in an SSR-configured application it will throw an
ERROR ReferenceError: document is not defined.
upon initialization. It seems that the notification doesn't check if the document is available, like our Dialogs package.To Reproduce Open and run the local project. A17-notifications-ssr (1).zip
Workaround Checking the platform before initializing the NotificationService: