2017-02-12 91 views
0

我想从Angular JS连接到Firebase。Angularfire无法定义参考

我的控制器:

.controller('mynew',['$scope', '$firebaseArray', function($scope, $firebaseArray) { 
    var ref = firebase.database('https://myappurl.firebaseio.com/contacts').ref(); 
    $scope.contacts = $firebaseArray(ref); 
    console.log($scope.contacts); 
}]); 

这是正确的方法包括在database(??)的火力分贝网址是什么?

版本: 火力地堡v3.6.9 Angularfire V2.3.0

我在做什么错?

回答

1

需要初始化你的火力数据库这种方式(省略你不需要的数据):

// Initialize the Firebase SDK 
    var config = { 
    apiKey: '<your-api-key>', 
    authDomain: '<your-auth-domain>', 
    databaseURL: '<your-database-url>', 
    storageBucket: '<your-storage-bucket>' 
    }; 
    firebase.initializeApp(config); 

再经过该数据库()将intialized。

看到这个从文档:

app.controller("SampleCtrl", function($scope, $firebaseObject) { 
    var ref = firebase.database().ref(); 
    // download the data into a local object 
    $scope.data = $firebaseObject(ref); 
    // putting a console.log here won't work, see below 
}); 

请参阅该文档这里getting started

+0

就像一个魅力。万分感谢。有没有一个页面可以参考关于AngularJS在Firebase上查询的文档。不是Angular2。只是简单的查询。再次感谢。 – Somename

+1

没问题。下载[AngularFire]文档(https://www.firebase.com/docs/web/libraries/angular/api.html):) – matt