Firebase angularfire in new firebase

后端 未结 3 1409
名媛妹妹
名媛妹妹 2021-02-10 21:54

I have an angular app, which utilizes the angularFire library. It is stated in the firebase documentation that angularfire is supported https://firebase.google.com/support/guide

相关标签:
3条回答
  • 2021-02-10 22:31

    I'm using the latest version in one of my projects and it works fine so you should have something like this:

    /// Main configuration of Firebase
    
        var config = {
            apiKey: "AIzaSyDcPq_z9vh4CidkzFDyerRK0ZS7gs2Sj14",
            authDomain: "citytimer-90920.firebaseapp.com",
            databaseURL: "https://citytimer-90920.firebaseio.com",
            storageBucket: "citytimer-90920.appspot.com",
            messagingSenderId: "497040832817"
        };
        firebase.initializeApp(config);
    

    This part is pure Javascript so you don't need to include it in an Angular file.

    Then those are the Angular files I'm using.

    /// Database service
    
        function firebaseDataService() {
            var root = firebase.database().ref();
    
            var service = {
                root: root,
                requests: root.child('requests'),
                places: root.child('places')
            };
    
            return service;
        }
    

    As you can see my service looks like yours.

    /// Specific service to retrieve data
    
    function cityTimerService($firebaseArray, firebaseDataService, $firebaseObject, $rootScope, $q, $http) {
    
            var service = {
                getRequestsByUser: getRequestsByUser,
            };
    
            return service;
    
            function getRequestsByUser(uid) {
                if (!requests) {
                    requests = $firebaseArray(firebaseDataService.requests.child(uid).child('userRequests'));
                }
                return requests;
            }
    }
    

    Basically you don't longer need to provide the FIREBASE_URL because it's part of the configuration object. For the record you can get this configuration object from your Firebase console.

    If you want to take a closer look on the code I have in my project you can do it here.

    0 讨论(0)
  • 2021-02-10 22:40

    Yes, AngularFire is supported with google's new firebase 3 and above.

    Along with that you can get the detailed documentation of it on : GitHub : https://github.com/firebase/angularfire

    0 讨论(0)
  • 2021-02-10 22:46

    AngularFire is now officially updated to support Firebase 3.x.x :)

    0 讨论(0)
提交回复
热议问题