Example of how to use OneSignal in an Angular application.
Note that, the official documentation isn't so good.
This project uses environment-specific configuration to manage OneSignal credentials securely.
-
Copy the example environment file:
cp src/environments/environment.example.ts src/environments/environment.local.ts
-
Update the local environment file with your actual OneSignal credentials: Edit
src/environments/environment.local.tsand replace the placeholder values:export const environment = { production: false, oneSignal: { appId: 'your-actual-onesignal-app-id', safariWebId: 'your-actual-safari-web-id' } };
-
Run the development server:
ng serve
This will automatically use your
environment.local.tsfile with your actual credentials.
For production builds, set the following environment variables:
NG_APP_ONESIGNAL_APP_ID: Your OneSignal App IDNG_APP_ONESIGNAL_SAFARI_WEB_ID: Your Safari Web ID
environment.local.ts- Local development environment (gitignored)environment.prod.ts- Production environment (uses environment variables)environment.example.ts- Template file for new developersenvironment.ts- Default fallback environment
The environment.local.ts file is automatically ignored by git to prevent committing sensitive credentials. Only the example file and production template are tracked in version control.
- Development (
ng serve): Usesenvironment.local.ts(your actual credentials) - Production (
ng build --configuration production): Usesenvironment.prod.tswith environment variables - Default
environment.ts: Contains placeholder values (safe to commit)