- 
                Notifications
    
You must be signed in to change notification settings  - Fork 2.2k
 
  Permalink
    
      
      
  
  
    
  
    
  
      
    
  
      
  
    
    
  
  
    
      Choose a base ref
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
    
    {{ refName }}
    default
  
           
        
        
          
            
              
              
           
        
       
     
  
  
  
    
  
    
  
    
  
      
    
  
      
  
    
    
  
  
    
      Choose a head ref
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
    
    {{ refName }}
    default
  
           
        
        
          
            
              
              
           
        
       
     
  
  
          
    
        
              
  
  
        
        
  
    
  
      
        
    
              
      
  
    
  
      
  
   
  Comparing changes
          Choose two branches to see what’s changed or to start a new pull request.
            If you need to, you can also    or
          learn more about diff comparisons.
  
Open a pull request
          Create a new pull request by comparing changes across two branches. If you need to, you can also   .
        Learn more about diff comparisons here.
  
base repository: angular/angularfire
        Failed to load repositories. Confirm that selected base ref is valid, then try again.
      
      
        
      Loading
      
  base: eb99d8e
Could not load branches
            
              
      Nothing to show
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
    
    {{ refName }}
    default
  
            
                
      Loading
              
            
      
      
        ...
      
head repository: ashishpatelcs/angularfire2
        Failed to load repositories. Confirm that selected head ref is valid, then try again.
      
      
        
      Loading
      
  compare: 81a1e31
Could not load branches
            
              
      Nothing to show
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
    
    {{ refName }}
    default
  
            
                
      Loading
              
            - 14 commits
 - 5 files changed
 - 1 contributor
 
Commits on Oct 21, 2018
- 
  
Configuration menu - View commit details
 - 
    
    
    
Copy full SHA for 42b3400  - Browse repository at this point
 
Copy the full SHA 42b3400View commit details  - 
  
# Upgrading to AngularFire2 4.0 AngularFire2 4.0 is a refactor of the AngularFire2 package which implements @NgModule, simplifies authentication, and better supports Angular 4. ### Removing `AngularFire` for Modularity Prior to 4.0, AngularFire2 did not take advantage of the Firebase SDK's modularity for tree shaking. The `AngularFire` service has now been removed and the library is broken up into smaller `@NgModule`s: * `AngularFireModule` * `AngularFireDatabaseModule` * `AngularFireAuthModule` When upgrading, replace calls to `AngularFire.database` and `AngularFire.auth` with `AngularFireDatabase` and `AngularFireAuth` respectively. ```typescript constructor(af: AngularFire) { af.database.list('foo'); af.auth; } ``` Should now be: ```typescript constructor(db: AngularFireDatabase, afAuth: AngularFireAuth) { db.list('foo'); afAuth.authState; } ``` ### Simplified Authentication API In 4.0 we've reduced the complexity of the auth module by providing only [`firebase.User`](https://firebase.google.com/docs/reference/js/firebase.User) observers (`AngularFireAuth.authState`, `AngularFireAuth.idToken`) and cutting the methods that were wrapping the Firebase SDK. ```typescript import { AngularFireAuth } from 'angularfire2/auth'; // Do not import from 'firebase' as you'd lose the tree shaking benefits import firebase from 'firebase/app'; ... user: Observable<firebase.User>; constructor(afAuth: AngularFireAuth) { this.user = afAuth.authState; // only triggered on sign-in/out (for old behavior use .idToken) } ``` AngularFire2 exposes the raw Firebase Auth object via `AngularFireAuth.auth`. For actions like login, logout, user creation, etc. you should use the [methods available to `firebase.auth.Auth`](https://firebase.google.com/docs/reference/js/firebase.auth.Auth). While convenient, the pre-configured login feature added unneeded complexity. `AngularFireModule.initializeApp` no longer takes a default sign in method. Sign in should be done with the Firebase SDK via `firebase.auth.Auth`: ```typescript login() { this.afAuth.auth.signInWithPopup(new firebase.auth.GoogleAuthProvider()); } logout() { this.afAuth.auth.signOut(); } ``` ### FirebaseListFactory and FirebaseObjectFactory API Changes If you directly use `FirebaseListFactory` or `FirebaseObjectFactory` you will no longer be able to pass in a string, it will instead expect a Firebase database reference. ## Putting this all together Here's an example of what AngularFire2 4.0 looks like: ```typescript import { NgModule, Component } from '@angular/core'; import { Observable } from 'rxjs/Observable'; import { AngularFireModule } from 'angularfire2'; import { AngularFireDatabaseModule, AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database'; import { AngularFireAuthModule, AngularFireAuth } from 'angularfire2/auth'; import { environment } from '../environments/environment'; // Do not import from 'firebase' as you'd lose the tree shaking benefits import firebase from 'firebase/app'; @NgModule({ declarations: [ App ], exports: [ App ], imports: [ AngularFireModule.initializeApp(environment.firebase, 'my-app'), AngularFireDatabaseModule, AngularFireAuthModule ], bootstrap: [ App ] }) export class MyModule { } ``` ```typescript @component({ selector: 'my-app', template: ` <div> {{ (items | async)? | json }} </div> <div> {{ (user | async)? | json }} </div> <button (click)="login()">Login</button> <button (click)="logout()">Logout</button> ` }) export class App { user: Observable<firebase.User>; items: FirebaseListObservable<any[]>; constructor(afAuth: AngularFireAuth, db: AngularFireDatabase) { this.user = afAuth.authState; this.items = db.list('items'); } login() { this.afAuth.auth.signInWithPopup(new firebase.auth.GoogleAuthProvider()); } logout() { this.afAuth.auth.signOut(); } } ```
Configuration menu - View commit details
 - 
    
    
    
Copy full SHA for 46d67a6  - Browse repository at this point
 
Copy the full SHA 46d67a6View commit details  - 
  
Configuration menu - View commit details
 - 
    
    
    
Copy full SHA for 7a9b89a  - Browse repository at this point
 
Copy the full SHA 7a9b89aView commit details  - 
  
Configuration menu - View commit details
 - 
    
    
    
Copy full SHA for dc78792  - Browse repository at this point
 
Copy the full SHA dc78792View commit details  - 
  
Configuration menu - View commit details
 - 
    
    
    
Copy full SHA for 333faa7  - Browse repository at this point
 
Copy the full SHA 333faa7View commit details  - 
  
Configuration menu - View commit details
 - 
    
    
    
Copy full SHA for 59e4337  - Browse repository at this point
 
Copy the full SHA 59e4337View commit details  - 
  
Merge pull request #1 from ashishpatelcs/patch-1
Minor grammar fix
Configuration menu - View commit details
 - 
    
    
    
Copy full SHA for 9fff1a2  - Browse repository at this point
 
Copy the full SHA 9fff1a2View commit details  - 
  
Merge pull request #2 from ashishpatelcs/patch-2
Update version-4-upgrade.md
Configuration menu - View commit details
 - 
    
    
    
Copy full SHA for bd2b5ad  - Browse repository at this point
 
Copy the full SHA bd2b5adView commit details  - 
  
Configuration menu - View commit details
 - 
    
    
    
Copy full SHA for d10cac2  - Browse repository at this point
 
Copy the full SHA d10cac2View commit details  - 
  
Merge pull request #3 from ashishpatelcs/patch-3
minor grammar fix
Configuration menu - View commit details
 - 
    
    
    
Copy full SHA for e46b202  - Browse repository at this point
 
Copy the full SHA e46b202View commit details  - 
  
  
Configuration menu - View commit details
 - 
    
    
    
Copy full SHA for 05bccbf  - Browse repository at this point
 
Copy the full SHA 05bccbfView commit details  - 
  
Merge pull request #5 from ashishpatelcs/patch-5
typo and grammar fixes
Configuration menu - View commit details
 - 
    
    
    
Copy full SHA for 03a408b  - Browse repository at this point
 
Copy the full SHA 03a408bView commit details  - 
  
  
Configuration menu - View commit details
 - 
    
    
    
Copy full SHA for c7b2e56  - Browse repository at this point
 
Copy the full SHA c7b2e56View commit details  - 
  
Configuration menu - View commit details
 - 
    
    
    
Copy full SHA for 81a1e31  - Browse repository at this point
 
Copy the full SHA 81a1e31View commit details  
        
      Loading
      
      This comparison is taking too long to generate.
Unfortunately it looks like we can’t render this comparison for you right now. It might be too big, or there might be something weird with your repository.
            You can try running this command locally to see the comparison on your machine: 
            git diff eb99d8e...81a1e31