Skip to content

Integration with AngularFire2

Neo Minchul Chae edited this page Dec 16, 2016 · 11 revisions

This page shows how to integrate angularfire2 (angularfire2@2.0.0-beta.6 & firebase@3.4.0) into the seed.

  1. Install angularfire2 and firebase:
npm install --save angularfire2@2.0.0-beta.6 firebase@3.4.0
npm install --save-dev @types/request@0.0.32
  1. Add angularfire2 to the types for the dependencies in src/client/tsconfig.json:
"types": [
  "core-js",
  "express",
  "jasmine",
  "node",
  "protractor",
  "systemjs",
  "angularfire2"
]
  1. In tools/config/project.config.ts, inside the ProjectConfig constructor:
constructor() {
...
    // Add Firebase configuration to SystemJS
    this.addPackageBundles({
      name: 'firebase',
      path: 'node_modules/firebase/',
      packageMeta: {
        main: 'firebase-browser.js',
        defaultExtension: 'js'
      }
    });

    // Add AngularFire configuration to SystemJS
    this.addPackageBundles({
      name: 'angularfire2',
      path: 'node_modules/angularfire2/bundles/angularfire2.umd.js',
      packageMeta: {
        main: 'angularfire2.js',
        defaultExtension: 'js'
      }
    });
...
}
  1. Add it to files in karma.conf.js for enabling testing with angularfire2:
    files: [
      ...
      // Insert it after angular dependencies

      //Firebase and AngularFire2
      { pattern: 'node_modules/firebase/**/*.js', included: false, watched: false },
      { pattern: 'node_modules/angularfire2/bundles/angularfire2.umd.js', included: false, watched: false },
      ...
    ],
  1. Add it to your app module at src/client/app/app.module.ts:
import { AngularFireModule } from 'angularfire2';

const FIREBASE_APP_CONFIG = {
  apiKey: '<->',
  authDomain: '<->',
  databaseURL: '<->',
  storageBucket: '<->',
};

...

@NgModule({
  imports: [
    ...
    AngularFireModule.initializeApp(FIREBASE_APP_CONFIG),
    ...
  ],
  declarations: [AppComponent],
  providers: [{
    provide: APP_BASE_HREF,
    useValue: '<%= APP_BASE %>'
  }],
  bootstrap: [AppComponent]
})

export class AppModule { }
  1. Use AngularFire2 in you code and tests!