项目作者: matanlurey

项目描述 :
Unofficial library for AngularDart and Firebase.
高级语言: Dart
项目地址: git://github.com/matanlurey/angular_fire.git
创建时间: 2017-05-30T02:22:29Z
项目社区:https://github.com/matanlurey/angular_fire

开源协议:BSD 3-Clause "New" or "Revised" License

下载



angular_fire



An unofficial library for AngularDart and Firebase.


pub package
Build Status

Install

The current stable release of angular_fire works best with the following:

  1. dependencies:
  2. angular2: ^3.1.0
  3. angular_fire: ^0.1.0
  4. firebase: ^3.1.0

To get started, you need to, at minimum, include the Firebase SDK:

  1. <body>
  2. <script src="https://www.gstatic.com/firebasejs/4.0.0/firebase.js"></script>
  3. </body>

Usage

Services

FirebaseAuth

A high-level authentication service. First setup for dependency injection:

  1. import 'package:angular2/angular2.dart';
  2. import 'package:angular2/platform/browser.dart';
  3. import 'package:angular_fire/angular_fire.dart';
  4. import 'package:firebase/firebase.dart' as sdk;
  5. main() {
  6. bootstrap(AngularFireExample, <dynamic>[
  7. provide(
  8. FirebaseAuth,
  9. useValue: new FirebaseAuth(
  10. sdk.initializeApp(
  11. apiKey: '...',
  12. authDomain: '...',
  13. databaseURL: '...',
  14. storageBucket: '...',
  15. ),
  16. ),
  17. ),
  18. ]);
  19. }

Then inject into your app and use. See GoogleSignInComponent
below for an example.

Components

GoogleSignInComponent

Displays a rendered sign in box for Google authentication that follows the
branding guidelines.



  1. import 'package:angular2/angular2.dart';
  2. import 'package:angular_fire/angular_fire.dart';
  3. @Component(
  4. selector: 'angular-fire-example',
  5. directives: const [
  6. GoogleSignInComponent,
  7. ],
  8. template: r'''
  9. <google-sign-in (trigger)="signIn()">
  10. </google-sign-in>
  11. ''',
  12. )
  13. class AngularFireExample {
  14. final FirebaseAuth _auth;
  15. void onTrigger() {
  16. _auth.signIn();
  17. }
  18. }

NOTE: To use this component, you must have the brand assets in your
web/assets directory, or use the [assetPath] property, or the
googleSignInAssetPath token at bootstrap time to configure the location of
your assets - for example on an external CDN.

IfFirebaseAuthDirective

Like ngIf, but shows content if the value matches the current authentication:

  1. <div *ifFirebaseAuth="true; let currentUser = currentUser">
  2. Logged in as: {{currentUser.displayName}}.
  3. <button (click)="signOut()">Sign Out</button>
  4. </div>
  5. <div *ifFirebaseAuth="false">
  6. Waiting for sign in...
  7. <br>
  8. <google-sign-in
  9. (trigger)="signIn()">
  10. </google-sign-in>
  11. </div>

Contributing

We welcome a diverse set of contributions, including, but not limited to:

For the stability of the API and existing users, consider opening an issue
first before implementing a large new feature or breaking an API. For smaller
changes (like documentation, bug fixes), just send a pull request.

Testing

Run the (simple) test suite in Dartium. It doesn’t currently run on Travis:

  1. $ pub run angular_test -p dartium