OneSignal with Angular 2

2k views Asked by At

My site is based on angular 2 and I want to show notification to user in the panel. So I used OneSignal for this purpose but there is a problem with it. when I added the OneSignal script the page content wont load and browser shows the blank page and when I remove the script of OneSignal everything is fine.

the load script which cause the problem :

<script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async='async'></script>

and the initialization of OneSignal inside component :

    ngOnInit(){
    var OneSignal = window['OneSignal'] || [];
    OneSignal.push(["init", {
        appId: "xxx-xxx-xxx",
        autoRegister: false, 
        subdomainName: 'https://something.onesignal.com',   
        httpPermissionRequest: {
            enable: true
        },
        notifyButton: {
            enable: true 
        }
    }]);

}
1

There are 1 answers

1
yurzui On

You need to load OneSignalSDK script before zonejs otherwise see picture below

https://plnkr.co/edit/lpal29dghPPl78yo4yur?p=preview enter image description here