Cordova-plugin-firebase: Using cordova-plugin-firebase with Angular. How?

Created on 27 May 2018  路  9Comments  路  Source: arnesson/cordova-plugin-firebase

I'm trying to use this plugin to receive a token to send push notfications with FCM.

Got an Angular project that i convert to an android app with cordova.
Now i somehow have to access the FirebasePlugin in my Angular project. But i have no clue how to do this and there is 0 documentation on how to do this.

Could anyone help me with this?

Most helpful comment

This took me sometime to find out, but here is how.

  1. Install plugin normally to your cordova project.

  2. Import cordova.js manually in your index.html (cordova.js file will be there, you don't have to copy it or anything)
    <script type="text/javascript" src="cordova.js"></script>

  3. Declare FirebasePlugin like this in your component
    declare var FirebasePlugin;

  4. Then you will be ready to use it. For example:

FirebasePlugin.onNotificationOpen((notification) => {
  console.log(notification);
});

You have to use the plugin after 'deviceready' event or it might not work. That will be achieved like this:

this.renderer.listenGlobal('document', 'deviceready', () => {
  FirebasePlugin.onNotificationOpen((notification) => {
    console.log(notification);
  });
});

Hope these steps will guide you to the correct path.

All 9 comments

This took me sometime to find out, but here is how.

  1. Install plugin normally to your cordova project.

  2. Import cordova.js manually in your index.html (cordova.js file will be there, you don't have to copy it or anything)
    <script type="text/javascript" src="cordova.js"></script>

  3. Declare FirebasePlugin like this in your component
    declare var FirebasePlugin;

  4. Then you will be ready to use it. For example:

FirebasePlugin.onNotificationOpen((notification) => {
  console.log(notification);
});

You have to use the plugin after 'deviceready' event or it might not work. That will be achieved like this:

this.renderer.listenGlobal('document', 'deviceready', () => {
  FirebasePlugin.onNotificationOpen((notification) => {
    console.log(notification);
  });
});

Hope these steps will guide you to the correct path.

@monn1 Thank you soooooo much. I will give this a try later today!

@monn1 this works perfectly fine.
Thank you so much, that was very helpful!

@monn1 where can i put the this.renderer.listenGlobal('document', 'deviceready', () => { FirebasePlugin.onNotificationOpen((notification) => { console.log(notification); }); }); in my angular component?

is this correct sir?
`import { Component, Renderer } from '@angular/core';

declare var FirebasePlugin;

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
constructor(renderer: Renderer) {
renderer.listenGlobal('document','deviceready', () => {
FirebasePlugin.onNotification((notification) => {
console.log(notification);
});
});
}
}`

thanks for response :)

@FavoriteFave how do you access in FirebasePlugin in your angular, thanks

closing as resolved

@monn1 's solution worked but I still had to add define the type:
declare var FirebasePlugin: any;
Now it runs perfectly!

renderer.listenGlobal('document','deviceready', () => {
console.log("Hello ");
but its not working ,I am using angular 8 and "cordova-plugin-firebase-lib": "^5.1.1",

renderer.listenGlobal('document','deviceready', () => {
console.log("Hello ");
but its not working ,I am using angular 8 and "cordova-plugin-firebase-lib": "^5.1.1",

hello, you find a solution?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

matthitachi picture matthitachi  路  5Comments

eilian92 picture eilian92  路  4Comments

ghost picture ghost  路  3Comments

DanielAccorsi picture DanielAccorsi  路  3Comments

JonSmart picture JonSmart  路  3Comments