angular-firebase
TypeScript icon, indicating that this package has built-in type declarations

1.1.6 • Public • Published

angular-firebase

A package to help you using firebase in angular and ionic in an easy way.

Installation

First, install the package using npm:

   $ npm install angular-firebase --save

Then, import the package in your app.module.ts like so:

import {FirebaseModule, FirebaseProvider} from 'angular-firebase'

@NgModule({
  imports: [
    FirebaseModule
  ],
  providers: [
    FirebaseProvider
  ]
})

Finally, Intialize your firebase in app.component.ts :

  import * as firebase from 'firebase';

  constructor() {
    const config = {
      // copy firebase configuration from your firebase project
    };
    firebase.initializeApp(config);
  }

Usage

First, Inject the service in the component you want to use firebase in:

   import {FirebaseProvider} from 'angular-firebase';

   constructor(private fb: FirebaseProvider) {
 
   }

Then, run the method you want from our service:

Example:

    this.fb.getDataArr('users','value',{limitToFirst:2}).then((v)=>{
      console.log(v)
    });

Notes

  • this package is depending on firebase main package.
  • this package installs the firebase package so you can use it normally.

angular-firebase methods

Authentication

  • signupMail(email,password)
    this.fb.signupMail('example@example.com','password').then((value) => {
      console.log(value); //return any validation message like 'this email not valid'
    });
  • signinMail(email,password)
    this.fb.signinMail('example@example.com','password').then((value) => {
      console.log(value); //return any validation message like 'the email or password not correct'
    });
  • signin3rdparty(credential)
    signin3rdparty(credential).then((value) => {
      console.log(value); //return any validation message.'
    });

note this used with facebook, Google, Twitter or GitHub just setup your firebase to use this authentication methods and prepare your authentication provider to allow firebase using it

after this you should download the library for the provider to authenticate with its account at last the authentication will return the credential witch used to sign in to firebas

  • signout()
    this.fb.signout();
    //will notify the firebase that this user signed out by removing the token
  • getProfile()
    this.fb.getProfile().then((v)=>{
      console.log(v);    //show loged in user data
    });
  • verificationMail()
    this.fb.verificationMail(); // send verification email to the current loged in user
  • authState()
    this.fb.authState().then((v)=>{
      console.log(v);   //show the current state of the user "logged in as true" or not as "false"
    })
  • resetPassword(email)
    // to send a reset password email
    this.fb.resetPassword("example@example.com").then((v)=>{
      console.log(v);   //show the state of the process faild or successfully
    })
  • updateEmail(password)
    this.fb.updateEmail("password").then((v)=>{
      console.log(v);   //show the state of the process faild or successfully
    })
  • updatePassword(password)
    this.fb.updatePassword("password").then((v)=>{
      console.log(v);   //show the state of the process faild or successfully
    })

Database

  • getData(path, orderby, query object)

path: the location you want to get data from

orderby: the data you want what type of sort you want ('value', 'key', 'parent' or 'child')

query: the firebase query Ex:{startAt : value }, {endAt : value }, {equalTo : value } , {limitToFirst : value } or {limitToLast : value } also you can mixing them like {endAt : value , limitToFirst : value }

    this.fb.getData('users','value',{limitToFirst:2}).then((v)=>{
      console.log(v)
    });
  • getDataArr(path, orderby, query object)

path: the location you want to get data from

orderby: the data you want what type of sort you want ('value', 'key', 'parent' or 'child:childKey')

query: the firebase query Ex:{startAt : value }, {endAt : value }, {equalTo : value } , {limitToFirst : value } or {limitToLast : value } also you can mixing them like {endAt : value , limitToFirst : value }

    this.fb.getDataArr('users','value',{limitToFirst:2}).then((v)=>{
      console.log(v)
    });
  • setData(path, data)
    this.fb.setData('users',data).then((v)=>{
      if(v==='success'){
        //..
      } else {
        console.log(v); //show error
      }
    });
  • pushData(path, data)
    this.fb.pushData('users',data).then((v)=>{
        console.log(v); //show the uid key generated for the pushed data
    });
  • moveFbRecord(pathMoveFrom, pathMoveTo)
    this.fb.moveFbRecord('users','whereToMove');
  • copyFbRecord(pathCopyFrom, pathCopyTo)
    this.fb.copyFbRecord('users','whereToCopy');
  • increase(path)
    this.fb.increase('pressNumber'); //to make a number in this path if not exist or increase it with 1.
  • decrease(path)
    this.fb.decrease('pressNumber'); 
  • deleteData(path)
    this.fb.deleteData('pathToRemove'); 
  • checkExist(path)
    this.fb.checkExist('users'); //check if there is a data in users path
  • startListen(path, callback_method, orderby, query object)
    this.fb.startListen('users', (v)=>{
      console.log(v)
    })
    ,'value',{limitToFirst:2})
  • startListenArr(path, callback_method, orderby, query object)
    this.fb.startListenArr('users', (v)=>{
      console.log(v);
    })
    ,'value',{limitToFirst:2});
  • stopListen(path)
    this.fb.stopListen('users');  //to stop any listener functions on this path

Storage

  • uploadFile(File, filePath, callback)
    this.firebase.uploadFile(file,'images/1.jpg',
    (v)=>{
        console.log(v)    //event detect the data uploaded  used to monitor the persentage of the download process
    }).then((v)=>{
        console.log(v)    //the url of uploaded file
    });
  • uploadString(encodedFile, filePath, fileType, callback)
    this.firebase.uploadString(encodedFile,'images/1.jpg','base64',
    (v)=>{
        console.log(v)    //event detect the data uploaded  used to monitor the persentage of the download process
    }).then((v)=>{
        console.log(v)    //the url of uploaded file
    });
  • removeFile(filePath, successfulCallback, failCallback)
    this.firebase.removeFile('images/1.jpg',
    ()=>{
        // run code after succesfuly removed file
    }), 
    (error)=>{
        console.log(error)    //show any failier error message
    })
  • getFileLink(filePath)
    this.firebase.getFileLink(filePath).then((url)=>{
        console.log(url);
    });

License

MIT

Dependents (0)

Package Sidebar

Install

npm i angular-firebase

Weekly Downloads

5

Version

1.1.6

License

MIT

Unpacked Size

70.9 kB

Total Files

15

Last publish

Collaborators

  • hegazy