Angularfire 无法定义 ref
Angularfire unable to define ref
我正在尝试从 Angular JS 连接到 firebase。
我的控制器:
.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);
}]);
这是将 firebase 数据库 url 包含在 database(??)
中的正确方法吗?
版本:
火力地堡 v3.6.9
Angularfire v2.3.0
我做错了什么?
您需要这样初始化您的 firebase 数据库(省略您不需要的数据):
// 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);
然后database()会被初始化。
从文档中查看:
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
的文档
我正在尝试从 Angular JS 连接到 firebase。
我的控制器:
.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);
}]);
这是将 firebase 数据库 url 包含在 database(??)
中的正确方法吗?
版本: 火力地堡 v3.6.9 Angularfire v2.3.0
我做错了什么?
您需要这样初始化您的 firebase 数据库(省略您不需要的数据):
// 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);
然后database()会被初始化。
从文档中查看:
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
的文档