Push Notifications In Angular With OneSignal

December 7, 2021 ยท View on GitHub

This project demonstrates the usage of OneSignal NPM package to add push notification to your Angular project.

How-to guide

Read our official how-to guide to demonstrate the usage of push notification using the OneSignal npm package and Angular.

Create a FREE OneSignal Account

Sign up for a free OneSignal account

OneSignal NPM Package

NPM Packge: OneSignal-Ngx

Install OneSignal NPM Package

npm i onesignal-ngx

Use OneSignal NPM Package

import { OneSignalService } from 'onesignal-ngx';

Use the OneSignal NPM Package

Initialize OneSignal with your OneSignal AppId:

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'angular-example-app';

  constructor(private oneSignal: OneSignalService) {
    this.oneSignal.init({
      appId: "YOUR-ONESIGNAL-APP-ID-HERE",
    });
  }
}

Add Tags To Segment Users

If you want to learn more about OneSignal data tags to segment your users, visti our official docs.

this.os.sendTag("tech", tag).then(() => {
  console.log("Sent tag: " + tag);
});